// conditions_endpoint.go defines the /conditions/current endpoint behavior.
// Layer: adapters/inbound/httpapi current-conditions 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 conditionsDefinition(svc Service) endpoint.Definition {
	return endpoint.GET(
		"/conditions/current",
		bindPrecisionQuery,
		func(ctx context.Context, req precisionQueryRequest) (any, error) {
			conditions, err := svc.CurrentConditions(ctx)
			if err != nil {
				return nil, err
			}
			return response.Envelope{Data: presenter.CurrentConditionsPayload(conditions, req.Units, req.Precision)}, nil
		},
		endpoint.WithProduces(render.FormatJSON, render.FormatXML, render.FormatText),
		endpoint.WithTemplate("conditions_current.txt.tmpl"),
	)
}
