package bundle

import (
	"context"
	"fonchain-fiee/api/bundle"
	"fonchain-fiee/pkg/service"
	"fonchain-fiee/pkg/utils"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
)

func GetReconciliationList(c *gin.Context) {
	var req bundle.GetReconciliationListReq
	if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
		service.Error(c, err)
		return
	}
	detail, detailErr := service.BundleProvider.GetReconciliationList(context.Background(), &req)
	if detailErr != nil {
		service.Error(c, detailErr)
		return
	}
	service.Success(c, detail)
	return

}

func GetReconciliationListDownload(c *gin.Context) {
	var req bundle.GetReconciliationListReq
	if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
		service.Error(c, err)
		return
	}
	detail, detailErr := service.BundleProvider.GetReconciliationList(context.Background(), &req)
	if detailErr != nil {
		service.Error(c, detailErr)
		return
	}
	titleList := []string{
		"关联套餐订单号", "关联增值服务订单号", "对账单创建时间", "艺人", "艺人手机号", "套餐", "支付金额", "币种", "支付渠道", "支付时间", "支付状态", "流水号",
	}
	var dataList []interface{}

	for _, i := range detail.List {
		payStatus := GetPayStatusText(i.PayStatus)
		currencyType := GetCurrencyTypeText(i.CurrencyType)
		payChannel := "未知"
		if i.PayChannel == 1 {
			payChannel = "支付宝"
		}
		data := []any{
			i.BundleOrderOn,
			i.BundleAddOrderOn,
			i.CreationTime,
			i.UserName,
			i.UserTel,
			i.BundleName,
			i.PayAmount,
			currencyType,
			payChannel,
			i.PayTime,
			payStatus,
			i.SerialNumber,
		}
		dataList = append(dataList, &data)
	}
	content, err := utils.ToExcelByType(titleList, dataList, "slice", "")
	if err != nil {
		service.Error(c, err)
		return
	}
	utils.ResponseXls(c, content, "对账单")
	return

}