package department_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 UpdateDepartmentAdminLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	r      *http.Request
}

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

func (l *UpdateDepartmentAdminLogic) UpdateDepartmentAdmin(req *types.DepartmentInfo) error {
	var updateModel core.DepartmentInfo
	_ = copier.Copy(&updateModel, req)

	_, err := l.svcCtx.CoreRpc.UpdateDepartment(l.ctx, &updateModel)
	if err != nil {
		return err
	}
	return nil
}
