import org.breezyweather.unit.temperature.Temperature;

CREATE TABLE normals(
    _id INTEGER NOT NULL PRIMARY KEY,
    location_formatted_id TEXT NOT NULL,

    month INTEGER NOT NULL,
    temperature_max_average INTEGER AS Temperature,
    temperature_min_average INTEGER AS Temperature,

    UNIQUE(location_formatted_id, month) ON CONFLICT REPLACE,
    FOREIGN KEY(location_formatted_id) REFERENCES locations (formatted_id)
    ON DELETE CASCADE
);

CREATE INDEX normals_location_formatted_id_index ON normals(location_formatted_id);

getNormalsByLocationId:
SELECT month, temperature_max_average, temperature_min_average
FROM normals
WHERE location_formatted_id = :locationFormattedId
ORDER BY month;

insert:
INSERT INTO normals(location_formatted_id, month, temperature_max_average, temperature_min_average)
VALUES (:locationFormattedId, :month, :temperatureMaxAverage, :temperatureMinAverage);

deleteNormalsForLocationId:
DELETE FROM normals
WHERE location_formatted_id = :locationFormattedId;
