package dto

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

type SpiderListenSymbolGetPageReq struct {
	dto.Pagination `search:"-"`
	Symbol         string `form:"symbol"  search:"type:contains;column:symbol;table:spider_listen_symbol" comment:"交易对"`
	SpiderListenSymbolOrder
}

type SpiderListenSymbolOrder struct {
	Id        string `form:"idOrder"  search:"type:order;column:id;table:spider_listen_symbol"`
	Symbol    string `form:"symbolOrder"  search:"type:order;column:symbol;table:spider_listen_symbol"`
	Coin      string `form:"coinOrder"  search:"type:order;column:coin;table:spider_listen_symbol"`
	Currency  string `form:"currencyOrder"  search:"type:order;column:currency;table:spider_listen_symbol"`
	CreatedAt string `form:"createdAtOrder"  search:"type:order;column:created_at;table:spider_listen_symbol"`
	UpdatedAt string `form:"updatedAtOrder"  search:"type:order;column:updated_at;table:spider_listen_symbol"`
	DeletedAt string `form:"deletedAtOrder"  search:"type:order;column:deleted_at;table:spider_listen_symbol"`
	CreateBy  string `form:"createByOrder"  search:"type:order;column:create_by;table:spider_listen_symbol"`
	UpdateBy  string `form:"updateByOrder"  search:"type:order;column:update_by;table:spider_listen_symbol"`
}

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

type SpiderListenSymbolInsertReq struct {
	Id       int    `json:"-" comment:"主键"` // 主键
	Symbol   string `json:"symbol" comment:"交易对"`
	Coin     string `json:"coin" comment:"代币"`
	Currency string `json:"currency" comment:"计价货币"`
	common.ControlBy
}

func (s *SpiderListenSymbolInsertReq) Valid() error {

	if s.Coin == "" {
		return errors.New("代币不能为空")
	}

	if s.Coin == "" {
		return errors.New("代币不能为空")
	}

	return nil
}

func (s *SpiderListenSymbolInsertReq) Generate(model *models.SpiderListenSymbol) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}

	model.Coin = strings.ToUpper(s.Coin)
	model.Currency = strings.ToUpper(s.Currency)
	model.Symbol = model.Coin + model.Currency
	model.CreateBy = s.CreateBy // 添加这而，需要记录是被谁创建的
}

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

type SpiderListenSymbolUpdateReq struct {
	Id       int    `uri:"id" comment:"主键"` // 主键
	Symbol   string `json:"symbol" comment:"交易对"`
	Coin     string `json:"coin" comment:"代币"`
	Currency string `json:"currency" comment:"计价货币"`
	common.ControlBy
}

func (s *SpiderListenSymbolUpdateReq) Valid() error {

	if s.Coin == "" {
		return errors.New("代币不能为空")
	}

	if s.Coin == "" {
		return errors.New("代币不能为空")
	}

	return nil
}

func (s *SpiderListenSymbolUpdateReq) Generate(model *models.SpiderListenSymbol) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	// model.Symbol = s.Symbol
	model.Coin = strings.ToUpper(s.Coin)
	model.Currency = strings.ToUpper(s.Currency)
	model.Symbol = model.Coin + model.Currency
	model.UpdateBy = s.UpdateBy // 添加这而，需要记录是被谁更新的
}

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

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

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

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

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