// forecast_mapper.go maps forecast rows into weather model payloads.
// Layer: adapters/outbound/postgres forecast feature.
package postgres

import "gitea.maximumdirect.net/ejr/weatherfeeder/model"

func mapForecastParentRow(row forecastParentRow) model.WeatherForecastRun {
	return model.WeatherForecastRun{
		LocationID:      stringValue(row.LocationID),
		LocationName:    stringValue(row.LocationName),
		IssuedAt:        row.IssuedAt.UTC(),
		UpdatedAt:       timePtr(row.UpdatedAt),
		Product:         model.ForecastProduct(row.Product),
		Latitude:        float64Ptr(row.Latitude),
		Longitude:       float64Ptr(row.Longitude),
		ElevationMeters: float64Ptr(row.ElevationMeters),
	}
}

func mapForecastPeriodRow(row forecastPeriodRow) model.WeatherForecastPeriod {
	return model.WeatherForecastPeriod{
		StartTime:                         row.StartTime.UTC(),
		EndTime:                           row.EndTime.UTC(),
		Name:                              stringValue(row.Name),
		IsDay:                             boolPtr(row.IsDay),
		ConditionCode:                     model.WMOCode(row.ConditionCode),
		ConditionText:                     stringValue(row.ConditionText),
		ProviderRawDescription:            stringValue(row.ProviderRawDescription),
		TextDescription:                   stringValue(row.TextDescription),
		DetailedText:                      stringValue(row.DetailedText),
		IconURL:                           stringValue(row.IconURL),
		TemperatureC:                      float64Ptr(row.TemperatureC),
		TemperatureCMin:                   float64Ptr(row.TemperatureCMin),
		TemperatureCMax:                   float64Ptr(row.TemperatureCMax),
		DewpointC:                         float64Ptr(row.DewpointC),
		RelativeHumidityPercent:           float64Ptr(row.RelativeHumidityPercent),
		WindDirectionDegrees:              float64Ptr(row.WindDirectionDegrees),
		WindSpeedKmh:                      float64Ptr(row.WindSpeedKmh),
		WindGustKmh:                       float64Ptr(row.WindGustKmh),
		BarometricPressurePa:              float64Ptr(row.BarometricPressurePa),
		VisibilityMeters:                  float64Ptr(row.VisibilityMeters),
		ApparentTemperatureC:              float64Ptr(row.ApparentTemperatureC),
		CloudCoverPercent:                 float64Ptr(row.CloudCoverPercent),
		ProbabilityOfPrecipitationPercent: float64Ptr(row.ProbabilityOfPrecipitationPercent),
		PrecipitationAmountMm:             float64Ptr(row.PrecipitationAmountMM),
		SnowfallDepthMM:                   float64Ptr(row.SnowfallDepthMM),
		UVIndex:                           float64Ptr(row.UVIndex),
	}
}
