package agent

import (
	"net/http"

	"ycc-server/app/main/api/internal/logic/agent"
	"ycc-server/app/main/api/internal/svc"
	"ycc-server/app/main/api/internal/types"
	"ycc-server/common/result"
	"ycc-server/pkg/lzkit/validator"

	"github.com/zeromicro/go-zero/rest/httpx"
)

func SaveAgentMembershipUserConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.SaveAgentMembershipUserConfigReq
		if err := httpx.Parse(r, &req); err != nil {
			result.ParamErrorResult(r, w, err)
			return
		}
		if err := validator.Validate(req); err != nil {
			result.ParamValidateErrorResult(r, w, err)
			return
		}
		l := agent.NewSaveAgentMembershipUserConfigLogic(r.Context(), svcCtx)
		err := l.SaveAgentMembershipUserConfig(&req)
		result.HttpResult(r, w, nil, err)
	}
}
