package dto

import (
	"errors"
	"go-admin/app/admin/models"
	"go-admin/common/dto"
	common "go-admin/common/models"
)

type LineSymbolGetPageReq struct {
	dto.Pagination `search:"-"`
	ExchangeType   string `form:"exchangeType" search:"type:exact;column:exchange_type;table:line_symbol"`
	Symbol         string `form:"symbol"  search:"type:contains;column:symbol;table:line_symbol" comment:"交易对"`
	BaseAsset      string `form:"baseAsset"  search:"type:contains;column:base_asset;table:line_symbol" comment:"基础货币"`
	QuoteAsset     string `form:"quoteAsset"  search:"type:exact;column:quote_asset;table:line_symbol" comment:"计价货币"`
	Type           string `form:"type"  search:"type:exact;column:type;table:line_symbol" comment:"交易对类型"`
	// StrategyTemplateId int    `form:"strategyTemplateId" search:"-" comment:"策略id"`
	LineSymbolOrder
}

type LineSymbolExportResp struct {
	ExchangeType string `json:"exchangeType"  excel:"交易所"`
	Symbol       string `json:"symbol" excel:"交易对"`
	Coin         string `json:"coin" excel:"基础货币"`
	Currency     string `json:"currency" excel:"计价货币"`
	SymbolType   string `json:"symbolType" excel:"交易对类型"`
	LastPrice    string `json:"lastPrice" excel:"最新价"`
}

type LineSymbolOrder struct {
	Id         string `form:"idOrder"  search:"type:order;column:id;table:line_symbol"`
	ApiId      string `form:"apiIdOrder"  search:"type:order;column:api_id;table:line_symbol"`
	Symbol     string `form:"symbolOrder"  search:"type:order;column:symbol;table:line_symbol"`
	BaseAsset  string `form:"baseAssetOrder"  search:"type:order;column:base_asset;table:line_symbol"`
	QuoteAsset string `form:"quoteAssetOrder"  search:"type:order;column:quote_asset;table:line_symbol"`
	CreatedAt  string `form:"createdAtOrder"  search:"type:order;column:created_at;table:line_symbol"`
	UpdatedAt  string `form:"updatedAtOrder"  search:"type:order;column:updated_at;table:line_symbol"`
	DeletedAt  string `form:"deletedAtOrder"  search:"type:order;column:deleted_at;table:line_symbol"`
	CreateBy   string `form:"createByOrder"  search:"type:order;column:create_by;table:line_symbol"`
	UpdateBy   string `form:"updateByOrder"  search:"type:order;column:update_by;table:line_symbol"`
	Switch     string `form:"switchOrder"  search:"type:order;column:switch;table:line_symbol"`
	Type       string `form:"typeOrder"  search:"type:order;column:type;table:line_symbol"`
}

type LineSymbolGetListReq struct {
	ExchangeType string `json:"exchangeType" form:"exchangeType"`
	Type         string `json:"type" form:"type"`
}

func (req *LineSymbolGetListReq) Valid() error {
	if req.ExchangeType == "" {
		return errors.New("交易所不能为空")
	}

	return nil
}

func (m *LineSymbolGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type LineSymbolInsertReq struct {
	Id         int    `json:"-" comment:"id"` // id
	ApiId      string `json:"apiId" comment:"api账户id"`
	Symbol     string `json:"symbol" comment:"交易对"`
	BaseAsset  string `json:"baseAsset" comment:"基础货币"`
	QuoteAsset string `json:"quoteAsset" comment:"计价货币"`
	Switch     string `json:"switch" comment:"状态"`
	Type       string `json:"type" comment:"交易对类型"`
	common.ControlBy
}

func (s *LineSymbolInsertReq) Generate(model *models.LineSymbol) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.ApiId = s.ApiId
	model.Symbol = s.Symbol
	model.BaseAsset = s.BaseAsset
	model.QuoteAsset = s.QuoteAsset
	model.CreateBy = s.CreateBy // 添加这而，需要记录是被谁创建的
	model.Switch = s.Switch
	model.Type = s.Type
}

func (s *LineSymbolInsertReq) GetId() interface{} {
	return s.Id
}

type LineSymbolUpdateReq struct {
	Id         int    `uri:"id" comment:"id"` // id
	ApiId      string `json:"apiId" comment:"api账户id"`
	Symbol     string `json:"symbol" comment:"交易对"`
	BaseAsset  string `json:"baseAsset" comment:"基础货币"`
	QuoteAsset string `json:"quoteAsset" comment:"计价货币"`
	Switch     string `json:"switch" comment:"状态"`
	Type       string `json:"type" comment:"交易对类型"`
	common.ControlBy
}

func (s *LineSymbolUpdateReq) Generate(model *models.LineSymbol) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.ApiId = s.ApiId
	model.Symbol = s.Symbol
	model.BaseAsset = s.BaseAsset
	model.QuoteAsset = s.QuoteAsset
	model.UpdateBy = s.UpdateBy // 添加这而，需要记录是被谁更新的
	model.Switch = s.Switch
	model.Type = s.Type
}

func (s *LineSymbolUpdateReq) GetId() interface{} {
	return s.Id
}

// LineSymbolGetReq 功能获取请求参数
type LineSymbolGetReq struct {
	Id int `uri:"id"`
}

func (s *LineSymbolGetReq) GetId() interface{} {
	return s.Id
}

// LineSymbolDeleteReq 功能删除请求参数
type LineSymbolDeleteReq struct {
	Ids []int `json:"ids"`
}

func (s *LineSymbolDeleteReq) GetId() interface{} {
	return s.Ids
}
