package tmall

import (
	"context"
	"errors"
	"testing"

	"github.com/duke-git/lancet/v2/retry"
	"github.com/gogf/gf/v2/os/glog"
	"github.com/gogf/gf/v2/os/gtime"
)

func TestInnerClient_GetTradeGetListByCreatedTime(t *testing.T) {
	ctx := context.Background()
	//cli := topsdk.NewDefaultTopClient("34819216", "e1bd6702de814bdd0de91db9650d43de", "https://eco.taobao.com/router/rest", 1000*60*5, 1000*60*5)
	//retResponse, err := ability304.NewAbility304(&cli).TaobaoTopAuthTokenCreate(&request.TaobaoTopAuthTokenCreateRequest{
	//	Code: gconv.PtrString("uyECgAUCVg1WpCzxJ25AKpK82364674"),
	//})
	//glog.Info(ctx, retResponse.TokenResult)
	//glog.Error(ctx, err)
	glog.Info(ctx, gtime.Now().Sub(gtime.NewFromTimeStamp(1727399509000)))
	//glog.Info(ctx, gtime.NewFromTimeStamp(1727399509000))
	//startCreated := util.LocalTime(time.Now().Add(-time.Hour * 30))
	//var pageNo int64 = 1
	//result, err2 := ability648.NewAbility648(&cli).TaobaoTradesSoldGet(&request.TaobaoTradesSoldGetRequest{
	//	StartCreated: &startCreated,
	//	Fields:       &[]string{"tid", "type", "status", "payment", "orders"},
	//	PageNo:       &pageNo,
	//	Status:       gconv.PtrString(tmall.ENUM_TRADE_FINISHED),
	//	RateStatus:   gconv.PtrString(tmall.ENUM_RATE_BUYER_SELLER),
	//	PageSize:     gconv.PtrInt64(100),
	//}, "6200520979129e0acd3ed2db5515ZZc1f3d74fdb0b279032217820516196")
	//glog.Info(ctx, result.Trades)
	//glog.Error(ctx, err2)
	//tbBaseTrade, _ := ability648.NewAbility648(&cli).TaobaoTradeGet(&request.TaobaoTradeGetRequest{
	//	Tid:    gconv.PtrInt64(4052869815792225937),
	//	Fields: &[]string{"tid", "buyer_nick", "type", "status", "buyer_memo", "payment", "end_time", "created", "seller_rate", "buyer_rate", "total_fee", "pay_time", "end_time", "modified", "consign_time", "buyer_memo", "seller_memo", "alipay_no", "buyer_message"},
	//}, "6200520979129e0acd3ed2db5515ZZc1f3d74fdb0b279032217820516196")
	go func() {
		if err3 := retry.Retry(func() error {
			//tbBaseTrade, _ := ability648.NewAbility648(&cli).TaobaoTradeFullinfoGet(&request.TaobaoTradeFullinfoGetRequest{
			//	Tid:    gconv.PtrInt64(4052869815792225937),
			//	Fields: &[]string{"tid", "buyer_nick", "type", "status", "receiver_address", "buyer_memo", "payment", "end_time", "created", "seller_rate", "buyer_rate", "total_fee", "pay_time", "end_time", "modified", "consign_time", "buyer_memo", "seller_memo", "alipay_no", "buyer_message"},
			//}, "6200520979129e0acd3ed2db5515ZZc1f3d74fdb0b279032217820516196")
			return errors.New("淘宝授权错误")
		}, retry.Context(ctx)); err3 != nil {
			glog.Error(ctx, err3)
		}
	}()
	//取消ctx
	//tbTrade := tbBaseTrade.Trade
	//result := model.UpdateAgisoCallBackInfoInput{
	//	TMallOrderId: gconv.Int(tbTrade.Tid),
	//	Created:      gconv.GTime(tbTrade.Created),
	//	BuyerNick:    gconv.String(tbTrade.BuyerNick),
	//	Status:       consts.RechargeTMallGameOrderStatusPaid,
	//	BuyerRate:    gconv.Int(*tbTrade.BuyerRate),
	//	TradeStatus:  gconv.String(tbTrade.Status),
	//	Payment:      gconv.String(tbTrade.Payment),
	//	TotalFee:     gconv.String(tbTrade.TotalFee),
	//	PayTime:      gconv.GTime(&tbTrade.PayTime),
	//	BuyerMemo:    gconv.String(tbTrade.BuyerMemo),
	//	AlipayNo:     gconv.String(tbTrade.AlipayNo),
	//	BuyerMessage: gconv.String(tbTrade.BuyerMessage),
	//	OriginalData: string(gjson.MustEncode(tbTrade)),
	//	SourceType:   consts.RechargeTMallGameShopSourceTypeTMall,
	//}
	//glog.Info(ctx, result)

	//result2, err2 := ability648.NewAbility648(&cli).TaobaoTraderateAdd(&request.TaobaoTraderateAddRequest{
	//	Result:  utils.StringPtr("good"),
	//	Role:    utils.StringPtr("seller"),
	//	Tid:     utils.Int64Ptr(2301531997518477282),
	//	Content: utils.StringPtr("买家不错💐💐💐"),
	//}, "6200520979129e0acd3ed2db5515ZZc1f3d74fdb0b279032217820516196")
	//glog.Info(ctx, result2)
	//glog.Error(ctx, err2)
	//result2, err2 := defaultability.NewDefaultability(&cli).TaobaoTraderateExplainAdd(&request.TaobaoTraderateExplainAddRequest{
	//	Oid:   gconv.PtrInt64(2301531997518477282),
	//	Reply: gconv.PtrString("好"),
	//}, "6200520979129e0acd3ed2db5515ZZc1f3d74fdb0b279032217820516196")
	//glog.Info(ctx, result2)
	//glog.Error(ctx, err2)
	//result, err := defaultability.NewDefaultability(&cli).TaobaoTmcMessageProduce(&request.TaobaoTmcMessageProduceRequest{
	//	Content: gconv.PtrString(fmt.Sprintf("{\"tid\":2895732958732,\"seller_nick\":\"helloworld\"}")),
	//	Topic:   gconv.PtrString("taobao_trade_TradeCreate"),
	//	//MediaContent: nil,
	//}, "610200071388bfd1dcecfe1aaf9344c9a6c97a2f4e715692217820516196")
	//glog.Info(ctx, result)
	//glog.Error(ctx, err)
	//result, err := defaultability.NewDefaultability(&cli).TaobaoRpRefundsAgree(&request.TaobaoRpRefundsAgreeRequest{
	//	IgnoreCode:  gconv.PtrBool(true),
	//	RefundInfos: gconv.PtrString("43234234|20000|1409294148714,3123123|12000|1409294148715\t"),
	//	//MediaContent: nil,
	//}, "610200071388bfd1dcecfe1aaf9344c9a6c97a2f4e715692217820516196")
	//glog.Info(ctx, tbBaseTrade)
	//glog.Error(ctx, err)
}
