package card_t_mall_order

import (
	"context"
	"kami/internal/dao"
	"kami/internal/model"
	"kami/internal/model/do"
	"kami/internal/model/entity"
	"kami/utility/config"

	"github.com/gogf/gf/v2/database/gdb"
)

func (h *sRechargeTMallGameOrder) AddOrderHistory(ctx context.Context, input *model.AddAgisoCallBackHistoryInput, tx gdb.TX) (err error) {
	m := dao.V1RechargeTMallOrderHistory.Ctx(ctx).DB(config.GetDatabaseV1())
	if tx != nil {
		m = m.TX(tx)
	}
	_, err = m.Insert(do.V1RechargeTMallOrderHistory{
		OrderNo:      input.OrderNo,
		OriginalData: input.OriginalData,
		Status:       input.Status,
		SourceType:   input.SourceType,
		Remark:       input.Remark,
	})
	return
}

func (h *sRechargeTMallGameOrder) AddShopHistory(ctx context.Context, input *model.AddOrderShopHistoryInput, tx gdb.TX) (err error) {
	m := dao.V1RechargeTMallShopHistory.Ctx(ctx).DB(config.GetDatabaseV1())
	if tx != nil {
		m = m.TX(tx)
	}
	_, err = m.Insert(do.V1RechargeTMallShopHistory{
		ShopId:  input.ShopId,
		RawData: input.RawData,
		Remark:  input.Remark,
		Status:  input.Status,
	})
	return
}

// GetHistoryList 获取订单详情
func (h *sRechargeTMallGameOrder) GetHistoryList(ctx context.Context, orderNo string) (output []*entity.V1RechargeTMallOrderHistory, err error) {
	output = make([]*entity.V1RechargeTMallOrderHistory, 0)
	err = dao.V1RechargeTMallOrderHistory.Ctx(ctx).DB(config.GetDatabaseV1()).Where(dao.V1RechargeTMallOrderHistory.Columns().OrderNo, orderNo).
		Scan(&output)
	return
}

// GetShopHistoryList 获取淘宝订单详情
func (h *sRechargeTMallGameOrder) GetShopHistoryList(ctx context.Context, shopId int64) (output []*entity.V1RechargeTMallShopHistory, err error) {
	output = make([]*entity.V1RechargeTMallShopHistory, 0)
	err = dao.V1RechargeTMallShopHistory.Ctx(ctx).DB(config.GetDatabaseV1()).
		Where(dao.V1RechargeTMallShopHistory.Columns().ShopId, shopId).
		Scan(&output)
	return
}
