package dict

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

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

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