package client

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

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

func (l *GetClientListLogic) GetClientList(req *types.ClientListReq) (interface{}, error) {
	resp, err := l.svcCtx.SystemRpc.GetClientList(l.ctx, &system.ClientListReq{
		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, "current": req.Current, "size": req.PageSize}, nil
}
