// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package permission

import (
	"net/http"

	"gateway/internal/logic/permission"
	"gateway/internal/response"
	"gateway/internal/svc"
	"gateway/internal/types"

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

// 指派角色給使用者（預設 source=manual；source 來源由 SyncFromX 自動標）
func AssignUserRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.AssignUserRoleByUIDReq
		if err := httpx.Parse(r, &req); err != nil {
			response.Write(r.Context(), w, nil, response.WrapRequestError(err))
			return
		}
		if err := svcCtx.Validator.ValidateAll(&req); err != nil {
			response.Write(r.Context(), w, nil, response.WrapRequestError(err))
			return
		}

		l := permission.NewAssignUserRoleLogic(actorContext(r.Context(), r), svcCtx)
		data, err := l.AssignUserRole(&req)
		response.Write(r.Context(), w, data, err)
	}
}
