package role

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"sundynix-micro-go/app/system/api/internal/svc"
	"sundynix-micro-go/app/system/api/internal/types"
	"sundynix-micro-go/app/system/rpc/system"
)

type CreateRoleLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateRoleLogic {
	return &CreateRoleLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}

func (l *CreateRoleLogic) CreateRole(req *types.RoleReq) error {
	_, err := l.svcCtx.SystemRpc.CreateRole(l.ctx, &system.RoleReq{
		Name: req.Name, Code: req.Code, Sort: int32(req.Sort), MenuIds: req.MenuIds,
	})
	return err
}
