// discussion_endpoint.go defines the /discussion endpoint behavior.
// Layer: adapters/inbound/httpapi discussion route.
package httpapi

import (
	"context"

	"gitea.maximumdirect.net/ejr/feedapi/endpoint"
	"gitea.maximumdirect.net/ejr/feedapi/render"
	"gitea.maximumdirect.net/ejr/feedapi/response"
	"gitea.maximumdirect.net/ejr/weatherapi/internal/adapters/inbound/httpapi/presenter"
)

func discussionDefinition(svc Service) endpoint.Definition {
	return endpoint.GET(
		"/discussion",
		bindTimezoneQuery,
		func(ctx context.Context, req timezoneQueryRequest) (any, error) {
			run, err := svc.LatestForecastDiscussion(ctx)
			if err != nil {
				return nil, err
			}
			return response.Envelope{Data: presenter.DiscussionPayload(run, req.Units, req.Timezone)}, nil
		},
		endpoint.WithProduces(render.FormatJSON, render.FormatXML, render.FormatText),
		endpoint.WithTemplate("discussion.txt.tmpl"),
	)
}
