package dto

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

type LineDirectionGetPageReq struct {
	dto.Pagination `search:"-"`
	Symbol         string `form:"symbol"  search:"type:contains;column:symbol;table:line_direction" comment:"交易对"`
	Type           int64  `form:"type"  search:"type:exact;column:type;table:line_direction" comment:"交易对类型:1=现货,2=合约"`
	Direction      string `form:"direction"  search:"type:contains;column:direction;table:line_direction" comment:"预估方向"`
	LineDirectionOrder
}

type LineDirectionOrder struct {
	Id         string `form:"idOrder"  search:"type:order;column:id;table:line_direction"`
	Symbol     string `form:"symbolOrder"  search:"type:order;column:symbol;table:line_direction"`
	Type       string `form:"typeOrder"  search:"type:order;column:type;table:line_direction"`
	BuyPoint1  string `form:"buyPoint1Order"  search:"type:order;column:buy_point1;table:line_direction"`
	BuyPoint2  string `form:"buyPoint2Order"  search:"type:order;column:buy_point2;table:line_direction"`
	BuyPoint3  string `form:"buyPoint3Order"  search:"type:order;column:buy_point3;table:line_direction"`
	SellPoint1 string `form:"sellPoint1Order"  search:"type:order;column:sell_point1;table:line_direction"`
	SellPoint2 string `form:"sellPoint2Order"  search:"type:order;column:sell_point2;table:line_direction"`
	SellPoint3 string `form:"sellPoint3Order"  search:"type:order;column:sell_point3;table:line_direction"`
	Direction  string `form:"directionOrder"  search:"type:order;column:direction;table:line_direction"`
	AiAnswer   string `form:"aiAnswerOrder"  search:"type:order;column:ai_answer;table:line_direction"`
	CreatedAt  string `form:"createdAtOrder"  search:"type:order;column:created_at;table:line_direction"`
	UpdatedAt  string `form:"updatedAtOrder"  search:"type:order;column:updated_at;table:line_direction"`
	DeletedAt  string `form:"deletedAtOrder"  search:"type:order;column:deleted_at;table:line_direction"`
	CreateBy   string `form:"createByOrder"  search:"type:order;column:create_by;table:line_direction"`
	UpdateBy   string `form:"updateByOrder"  search:"type:order;column:update_by;table:line_direction"`
}

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

type LineDirectionInsertReq struct {
	Id         int    `json:"-" comment:""` //
	Symbol     string `json:"symbol" comment:"交易对"`
	Type       int64  `json:"type" comment:"交易对类型:1=现货,2=合约"`
	BuyPoint1  string `json:"buyPoint1" comment:"买入点一"`
	BuyPoint2  string `json:"buyPoint2" comment:"买入点二"`
	BuyPoint3  string `json:"buyPoint3" comment:"买入点三"`
	SellPoint1 string `json:"sellPoint1" comment:"卖出点一"`
	SellPoint2 string `json:"sellPoint2" comment:"卖出点二"`
	SellPoint3 string `json:"sellPoint3" comment:"卖出点三"`
	Direction  string `json:"direction" comment:"预估方向"`
	AiAnswer   string `json:"aiAnswer" comment:"AI智能分析"`
	common.ControlBy
}

func (s *LineDirectionInsertReq) Generate(model *models.LineDirection) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.Symbol = s.Symbol
	model.Type = s.Type
	model.BuyPoint1 = s.BuyPoint1
	model.BuyPoint2 = s.BuyPoint2
	model.BuyPoint3 = s.BuyPoint3
	model.SellPoint1 = s.SellPoint1
	model.SellPoint2 = s.SellPoint2
	model.SellPoint3 = s.SellPoint3
	model.Direction = s.Direction
	model.AiAnswer = s.AiAnswer
	model.CreateBy = s.CreateBy // 添加这而，需要记录是被谁创建的
}

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

type LineDirectionUpdateReq struct {
	Id         int    `uri:"id" comment:""` //
	Symbol     string `json:"symbol" comment:"交易对"`
	Type       int64  `json:"type" comment:"交易对类型:1=现货,2=合约"`
	BuyPoint1  string `json:"buyPoint1" comment:"买入点一"`
	BuyPoint2  string `json:"buyPoint2" comment:"买入点二"`
	BuyPoint3  string `json:"buyPoint3" comment:"买入点三"`
	SellPoint1 string `json:"sellPoint1" comment:"卖出点一"`
	SellPoint2 string `json:"sellPoint2" comment:"卖出点二"`
	SellPoint3 string `json:"sellPoint3" comment:"卖出点三"`
	Direction  string `json:"direction" comment:"预估方向"`
	AiAnswer   string `json:"aiAnswer" comment:"AI智能分析"`
	common.ControlBy
}

func (s *LineDirectionUpdateReq) Generate(model *models.LineDirection) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.Symbol = s.Symbol
	model.Type = s.Type
	model.BuyPoint1 = s.BuyPoint1
	model.BuyPoint2 = s.BuyPoint2
	model.BuyPoint3 = s.BuyPoint3
	model.SellPoint1 = s.SellPoint1
	model.SellPoint2 = s.SellPoint2
	model.SellPoint3 = s.SellPoint3
	model.Direction = s.Direction
	model.AiAnswer = s.AiAnswer
	model.UpdateBy = s.UpdateBy // 添加这而，需要记录是被谁更新的
}

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

// LineDirectionGetReq 功能获取请求参数
type LineDirectionGetReq struct {
	Id         int    `uri:"id"`
	Symbol     string `json:"symbol" form:"symbol"`
	SymbolType int    `json:"symbolType" form:"symbolType"`
}

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

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

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

type AddDirectionReq struct {
	AccountName string `json:"accountName" form:"accountName"`
	Password    string `json:"password" form:"password"`
	Symbol      string `json:"symbol" form:"symbol"`
	Type        string `json:"type" form:"type"`
	BuyPoint1   string `json:"buy_point1" form:"buy_point1"`
	BuyPoint2   string `json:"buy_point2" form:"buy_point2"`
	BuyPoint3   string `json:"buy_point3" form:"buy_point3"`
	SellPoint1  string `json:"sell_point1" form:"sell_point1"`
	SellPoint2  string `json:"sell_point2" form:"sell_point2"`
	SellPoint3  string `json:"sell_point3" form:"sell_point3"`
	Direction   string `json:"direction" form:"direction"`
	AiAnswer    string `json:"ai_answer" form:"ai_answer"`
}

func (a *AddDirectionReq) CheckParams() error {
	if a.AccountName == "" || a.Password == "" || a.Symbol == "" || a.Type == "" || a.BuyPoint1 == "" ||
		a.BuyPoint2 == "" || a.BuyPoint3 == "" || a.SellPoint1 == "" ||
		a.SellPoint2 == "" || a.SellPoint3 == "" || a.AiAnswer == "" {
		return errors.New("参数校验失败 传了空值")
	}

	a.BuyPoint1 = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(a.BuyPoint1, "，", "."), "。", "."), " ", "")
	a.BuyPoint2 = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(a.BuyPoint2, "，", "."), "。", "."), " ", "")
	a.BuyPoint3 = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(a.BuyPoint3, "，", "."), "。", "."), " ", "")
	a.SellPoint1 = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(a.SellPoint1, "，", "."), "。", "."), " ", "")
	a.SellPoint2 = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(a.SellPoint2, "，", "."), "。", "."), " ", "")
	a.SellPoint3 = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(a.SellPoint3, "，", "."), "。", "."), " ", "")

	a.Symbol = utility.ReplaceSuffix(strings.ReplaceAll(a.Symbol, " ", ""), "4小时", "USDT")
	a.Symbol = strings.ReplaceAll(a.Symbol, "1小时", "USDT")
	a.Symbol = strings.ReplaceAll(a.Symbol, "1日", "USDT")
	a.Symbol = strings.ReplaceAll(a.Symbol, "四小时", "USDT")
	a.Symbol = strings.ReplaceAll(a.Symbol, "一小时", "USDT")
	a.Symbol = strings.ReplaceAll(a.Symbol, "一日", "USDT")

	return nil
}
