package handler

import (
	"net/http"

	"audio_transcoder/internal/logic"
	"audio_transcoder/internal/svc"
	"audio_transcoder/internal/types"
	"github.com/zeromicro/go-zero/rest/httpx"
)

func TranscoderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.Request
		if err := httpx.Parse(r, &req); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		l := logic.NewTranscoderLogic(r.Context(), svcCtx)
		resp, err := l.Transcoder(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJsonCtx(r.Context(), w, resp)
		}
	}
}
