package jobs

import (
	binancedto "go-admin/models/binancedto"
	"go-admin/services/binanceservice"

	DbModels "go-admin/app/admin/models"

	"github.com/go-admin-team/go-admin-core/logger"
	"github.com/shopspring/decimal"
)

type BinanceSpotAccountJob struct{}

type BinanceFuturesAccountJob struct{}

// 币安账户划转
func (t BinanceSpotAccountJob) Exec(arg interface{}) error {
	db := getDefaultDb()
	req := binancedto.BinanceTransfer{
		Type:       "MAIN_UMFUTURE",
		Asset:      "USDT",
		Amount:     decimal.NewFromFloat(0.1),
		FromSymbol: "USDT",
		ToSymbol:   "USDT",
	}
	var apis []DbModels.LineApiUser

	if err := db.Model(&DbModels.LineApiUser{}).Where("open_status = 1").Find(&apis).Error; err != nil {
		return err
	}

	for _, apiUserInfo := range apis {
		err := binanceservice.TradeAmount(db, &req, apiUserInfo)

		if err != nil {
			logger.Errorf("现货划转合约失败, err: %s", err)
		}
	}
	return nil
}

// 币安账户划转
func (t BinanceFuturesAccountJob) Exec(arg interface{}) error {
	db := getDefaultDb()
	req := binancedto.BinanceTransfer{
		Type:       "UMFUTURE_MAIN",
		Asset:      "USDT",
		Amount:     decimal.NewFromFloat(0.1),
		FromSymbol: "USDT",
		ToSymbol:   "USDT",
	}
	var apis []DbModels.LineApiUser
	if err := db.Model(&DbModels.LineApiUser{}).Where("open_status = 1").Find(&apis).Error; err != nil {
		return err
	}

	for _, apiUserInfo := range apis {
		err := binanceservice.TradeAmount(db, &req, apiUserInfo)

		if err != nil {
			logger.Errorf("合约划转现货失败, err: %s", err)
		}
	}

	return nil
}
