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 TestCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.OriginDataResponse
		if err := httpx.Parse(r, &req); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		l := logic.NewTestCallbackLogic(r.Context(), svcCtx)
		err := l.TestCallback(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.Ok(w)
		}
	}
}
