// Code generated by goctl. DO NOT EDIT.
// customized: HTTP 302 redirect for UTM tracking

package publicutm

import (
	"net/http"

	"apps/backend/internal/logic/publicutm"
	"apps/backend/internal/response"
	"apps/backend/internal/svc"
	"apps/backend/internal/types"

	"github.com/zeromicro/go-zero/rest/httpx"
)

func UtmRedirectHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.UtmRedirectReq
		if err := httpx.Parse(r, &req); err != nil {
			response.Write(r.Context(), w, nil, response.WrapRequestError(err))
			return
		}
		l := publicutm.NewUtmRedirectLogic(r.Context(), svcCtx)
		dest, err := svcCtx.Growth.TrackUtmClick(r.Context(), req.Code)
		if err != nil {
			response.Write(r.Context(), w, nil, err)
			return
		}
		_ = l
		http.Redirect(w, r, dest, http.StatusFound)
	}
}
