package ai

import (
	"encoding/json"
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/ai"
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
	dataset "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
	"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
	"io"
	"net/http"
)

func CreateDataSetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req dataset.CreateDatasetReq

		body, err := io.ReadAll(r.Body)
		if err != nil {
			result.ParamErrorResult(r, w, err)
			return
		}

		if err = json.Unmarshal(body, &req); err != nil {
			result.ParamErrorResult(r, w, err)
			return
		}

		l := ai.NewCreateDataSetLogic(r.Context(), svcCtx)
		resp, err := l.CreateDataSet(&req)
		result.HttpResult(r, w, resp, err)
	}
}
