package merchant

import (
	"context"
	"kami/api/commonApi"
	"kami/internal/model"
	"kami/internal/service"

	"github.com/duke-git/lancet/v2/slice"

	"kami/api/merchant/v1"
)

func (c *ControllerV1) StealList(ctx context.Context, req *v1.StealListReq) (res *v1.StealListRes, err error) {
	res = &v1.StealListRes{
		CommonPageRes: commonApi.CommonPageRes[*v1.MerchantHiddenConfigEntity]{
			CommonDataRes: commonApi.CommonDataRes[*v1.MerchantHiddenConfigEntity]{
				List: make([]*v1.MerchantHiddenConfigEntity, 0),
			},
			Total: 0,
		},
	}
	list, total, err := service.StealRule().List(ctx, &model.MerchantHiddenConfigList{StealListReq: req})
	res.Total = total
	slice.ForEach(list, func(index int, item *model.MerchantHiddenConfigOutput) {
		res.List = append(res.List, &item.MerchantHiddenConfigEntity)
	})
	return
}
