// conditions_mapper.go maps current-conditions DB rows into app models.
// Layer: adapters/outbound/postgres conditions feature.
package postgres

import (
	"gitea.maximumdirect.net/ejr/weatherapi/internal/app"
	"gitea.maximumdirect.net/ejr/weatherfeeder/model"
)

func mapCurrentConditionsRow(row currentConditionsRow) *app.CurrentConditions {
	if row.SampleCount == 0 {
		return nil
	}

	conditionCode := model.WMOUnknown
	if row.ConditionCode.Valid {
		conditionCode = model.WMOCode(row.ConditionCode.Int64)
	}

	return &app.CurrentConditions{
		TemperatureC:            float64Ptr(row.TemperatureC),
		ApparentTemperatureC:    float64Ptr(row.ApparentTemperatureC),
		DewpointC:               float64Ptr(row.DewpointC),
		RelativeHumidityPercent: float64Ptr(row.RelativeHumidityPercent),
		WindSpeedKmh:            float64Ptr(row.WindSpeedKmh),
		WindDirectionDegrees:    float64Ptr(row.WindDirectionDegrees),
		ConditionCode:           conditionCode,
		IsDay:                   boolPtr(row.IsDay),
	}
}
