package card_info_walmart

import (
	"context"

	v1 "kami/api/card_info_walmart/v1"
	"kami/internal/consts"
	"kami/internal/model"
	"kami/internal/service"

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

func (c *ControllerV1) OrderSummaryList(ctx context.Context, req *v1.OrderSummaryListReq) (res *v1.OrderSummaryListRes, err error) {
	res = &v1.OrderSummaryListRes{}

	list, err := service.CardRedeemOrder().SummaryWithOutAccount(ctx, req.GroupId, consts.CardRedeemAccountCategoryWalMart, req.AccountId, req.DateRange, nil)
	if err != nil {
		return nil, err
	}

	slice.ForEach(list, func(index int, item *model.RedeemCardSummaryWithOutAccountOutput) {
		res.List = append(res.List, &v1.OrderSummaryRecord{
			Date:     item.Date,
			Category: item.Category,
			Amount:   item.Amount,
			Count:    item.Count,
		})
	})
	return
}
