// discussion.go presents forecast discussion payloads.
// Layer: adapters/inbound/httpapi/presenter discussion payload mapping.
package presenter

import (
	"time"

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

func DiscussionPayload(run *model.WeatherForecastDiscussion, _ Units, tz *time.Location) any {
	if run == nil {
		return nil
	}

	out := model.WeatherForecastDiscussion{
		OfficeID:    run.OfficeID,
		OfficeName:  run.OfficeName,
		Product:     run.Product,
		IssuedAt:    inLocationTime(run.IssuedAt, tz),
		UpdatedAt:   inLocationTimePtr(run.UpdatedAt, tz),
		KeyMessages: append([]string(nil), run.KeyMessages...),
		ShortTerm:   copyDiscussionSection(run.ShortTerm, tz),
		LongTerm:    copyDiscussionSection(run.LongTerm, tz),
	}
	return &out
}

func copyDiscussionSection(in *model.WeatherForecastDiscussionSection, tz *time.Location) *model.WeatherForecastDiscussionSection {
	if in == nil {
		return nil
	}
	return &model.WeatherForecastDiscussionSection{
		Qualifier: in.Qualifier,
		IssuedAt:  inLocationTimePtr(in.IssuedAt, tz),
		Text:      in.Text,
	}
}
