package user_admin

import (
	"context"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
	"github.com/jinzhu/copier"

	"git.noahlan.cn/n-admin/n-admin-server/api/internal/svc"
	"git.noahlan.cn/n-admin/n-admin-server/api/internal/types"

	"net/http"
)

type CreateUserAdminLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	r      *http.Request
}

func NewCreateUserAdminLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserAdminLogic {
	return &CreateUserAdminLogic{
		r:      r,
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateUserAdminLogic) CreateUserAdmin(req *types.UserInfo) (resp *types.BaseID, err error) {
	var rpcReq core.UserInfo
	_ = copier.Copy(&rpcReq, req)
	rpcReq.ID = 0
	rpcReq.CreatedAt = ""
	rpcReq.UpdatedAt = ""
	rpcReq.Status = ""

	rpcResp, err := l.svcCtx.CoreRpc.CreateUser(l.ctx, &rpcReq)
	if err != nil {
		return nil, err
	}

	resp = &types.BaseID{ID: rpcResp.ID}
	return
}
