package ai

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

func CreateAlgorithmHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req algorithm.CreateAlgorithmReq

		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.NewCreateAlgorithmLogic(r.Context(), svcCtx)
		resp, err := l.CreateAlgorithm(&req)
		result.HttpResult(r, w, resp, err)
	}
}
