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 GetRoleListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

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

func (l *GetRoleListLogic) GetRoleList(req *types.RoleListReq) (interface{}, error) {
	resp, err := l.svcCtx.SystemRpc.GetRoleList(l.ctx, &system.RoleListReq{
		Current: int32(req.Current), PageSize: int32(req.PageSize), Name: req.Name,
	})
	if err != nil {
		return nil, err
	}
	return map[string]interface{}{"list": resp.List, "total": resp.Total}, nil
}
