package core

import (
	"github.com/zeromicro/go-zero/rest/httpx"
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/core"
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
	"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
	"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
	"net/http"
)

func CompareResourceSpecHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.FetchResourceSpecReq
		if err := httpx.Parse(r, &req); err != nil {
			result.ParamErrorResult(r, w, err)
			return
		}
		token := r.Header.Get("Authorization")
		// 获取用户信息
		jccUserInfo, err := utils.ParseTokenWithoutVerify(token)
		if err != nil {
			result.ParamErrorResult(r, w, err)
			return
		}
		req.UserId = jccUserInfo.Id
		l := core.NewCompareResourceSpecLogic(r.Context(), svcCtx)
		resp, err := l.CompareResourceSpec(&req)
		result.HttpResult(r, w, resp, err)
	}
}
