package merchant

import (
	"context"

	v1 "kami/api/merchant/v1"
	"kami/internal/model"
	"kami/internal/service"

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

func (c *ControllerV1) StealStats(ctx context.Context, req *v1.StealStatsReq) (res *v1.StealStatsRes, err error) {
	list, total, err := service.StealRule().Stats(ctx, &model.MerchantHiddenConfigStatsInput{
		StealStatsReq: req,
	})
	if err != nil {
		return nil, err
	}
	res = &v1.StealStatsRes{}
	res.Total = total
	res.List = slice.Map(list, func(_ int, item *model.MerchantHiddenConfigStatsOutput) *v1.StealStatsEntity {
		return &v1.StealStatsEntity{
			MerchantUid:  item.MerchantUid,
			TotalAmount:  item.TotalAmount,
			TotalCount:   item.TotalCount,
			ActualAmount: item.ActualAmount,
			ActualCount:  item.ActualCount,
			Date:         item.Date,
		}
	})
	return
}
