package dto

import (
	"time"

	"go-admin/app/admin/models"
	"go-admin/common/dto"
	common "go-admin/common/models"

	"github.com/shopspring/decimal"
)

type LineReverseOrderGetPageReq struct {
	dto.Pagination `search:"-"`
	OrderSn        string `form:"orderSn"  search:"type:contains;column:order_sn;table:line_reverse_order" comment:"订单号"`
	OrderId        string `form:"orderId"  search:"type:contains;column:order_id;table:line_reverse_order" comment:"币安订单号"`
	FollowOrderSn  string `form:"followOrderSn"  search:"type:contains;column:follow_order_sn;table:line_reverse_order" comment:"跟随币安订单号"`
	OrderType      int    `form:"orderType"  search:"type:exact;column:order_type;table:line_reverse_order" comment:"订单类型 0-主单 1-止损单 2-加仓 3-减仓"`
	PositionSide   string `form:"positionSide"  search:"type:exact;column:position_side;table:line_reverse_order" comment:"持仓方向 LONG-多 SHORT-空"`
	Side           string `form:"side"  search:"type:exact;column:side;table:line_reverse_order" comment:"买卖方向 SELL-卖 BUY-买"`
	Status         int    `form:"status"  search:"type:exact;column:status;table:line_reverse_order" comment:"状态 1-待下单 2-已下单 3-已成交 4-已平仓 5-已止损"`
	LineReverseOrderOrder
}

type LineReverseOrderOrder struct {
	Id            string `form:"idOrder"  search:"type:order;column:id;table:line_reverse_order"`
	PId           string `form:"pIdOrder"  search:"type:order;column:p_id;table:line_reverse_order"`
	OrderSn       string `form:"orderSnOrder"  search:"type:order;column:order_sn;table:line_reverse_order"`
	OrderId       string `form:"orderIdOrder"  search:"type:order;column:order_id;table:line_reverse_order"`
	FollowOrderSn string `form:"followOrderSnOrder"  search:"type:order;column:follow_order_sn;table:line_reverse_order"`
	Symbol        string `form:"symbolOrder"  search:"type:order;column:symbol;table:line_reverse_order"`
	OrderType     string `form:"orderTypeOrder"  search:"type:order;column:order_type;table:line_reverse_order"`
	BuyPrice      string `form:"buyPriceOrder"  search:"type:order;column:buy_price;table:line_reverse_order"`
	Price         string `form:"priceOrder"  search:"type:order;column:price;table:line_reverse_order"`
	PriceU        string `form:"priceUOrder"  search:"type:order;column:price_u;table:line_reverse_order"`
	FinalPrice    string `form:"finalPriceOrder"  search:"type:order;column:final_price;table:line_reverse_order"`
	PositionSide  string `form:"positionSideOrder"  search:"type:order;column:position_side;table:line_reverse_order"`
	Side          string `form:"sideOrder"  search:"type:order;column:side;table:line_reverse_order"`
	SignPrice     string `form:"signPriceOrder"  search:"type:order;column:sign_price;table:line_reverse_order"`
	TriggerTime   string `form:"triggerTimeOrder"  search:"type:order;column:trigger_time;table:line_reverse_order"`
	Status        string `form:"statusOrder"  search:"type:order;column:status;table:line_reverse_order"`
	CreatedAt     string `form:"createdAtOrder"  search:"type:order;column:created_at;table:line_reverse_order"`
	UpdatedAt     string `form:"updatedAtOrder"  search:"type:order;column:updated_at;table:line_reverse_order"`
	DeletedAt     string `form:"deletedAtOrder"  search:"type:order;column:deleted_at;table:line_reverse_order"`
	CreateBy      string `form:"createByOrder"  search:"type:order;column:create_by;table:line_reverse_order"`
	UpdateBy      string `form:"updateByOrder"  search:"type:order;column:update_by;table:line_reverse_order"`
}

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

type LineReverseOrderInsertReq struct {
	Id            int             `json:"-" comment:"主键id"` // 主键id
	PId           int             `json:"pId" comment:"主单id"`
	OrderSn       string          `json:"orderSn" comment:"订单号"`
	OrderId       string          `json:"orderId" comment:"币安订单号"`
	FollowOrderSn string          `json:"followOrderSn" comment:"跟随币安订单号"`
	Symbol        string          `json:"symbol" comment:"交易对"`
	OrderType     int             `json:"orderType" comment:"订单类型 0-主单 1-止损单 2-加仓 3-减仓"`
	BuyPrice      decimal.Decimal `json:"buyPrice" comment:"购买金额"`
	Price         decimal.Decimal `json:"price" comment:"委托价格"`
	PriceU        decimal.Decimal `json:"priceU" comment:"委托价格(U)"`
	FinalPrice    decimal.Decimal `json:"finalPrice" comment:"实际成交价"`
	PositionSide  string          `json:"positionSide" comment:"持仓方向 LONG-多 SHORT-空"`
	Side          string          `json:"side" comment:"买卖方向 SELL-卖 BUY-买"`
	SignPrice     decimal.Decimal `json:"signPrice" comment:"行情价"`
	TriggerTime   time.Time       `json:"triggerTime" comment:"触发时间"`
	Status        int             `json:"status" comment:"状态 1-待下单 2-已下单 3-已成交 4-已平仓 5-已止损"`
	common.ControlBy
}

func (s *LineReverseOrderInsertReq) Generate(model *models.LineReverseOrder) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.OrderSn = s.OrderSn
	model.OrderId = s.OrderId
	model.FollowOrderSn = s.FollowOrderSn
	model.Symbol = s.Symbol
	model.OrderType = s.OrderType
	model.BuyPrice = s.BuyPrice
	model.Price = s.Price
	model.PriceU = s.PriceU
	model.FinalPrice = s.FinalPrice
	model.PositionSide = s.PositionSide
	model.Side = s.Side
	model.SignPrice = s.SignPrice
	model.Status = s.Status
	model.CreateBy = s.CreateBy // 添加这而，需要记录是被谁创建的
}

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

type LineReverseOrderUpdateReq struct {
	Id            int             `uri:"id" comment:"主键id"` // 主键id
	PId           int             `json:"pId" comment:"主单id"`
	OrderSn       string          `json:"orderSn" comment:"订单号"`
	OrderId       string          `json:"orderId" comment:"币安订单号"`
	FollowOrderSn string          `json:"followOrderSn" comment:"跟随币安订单号"`
	Symbol        string          `json:"symbol" comment:"交易对"`
	OrderType     int             `json:"orderType" comment:"订单类型 0-主单 1-止损单 2-加仓 3-减仓"`
	BuyPrice      decimal.Decimal `json:"buyPrice" comment:"购买金额"`
	Price         decimal.Decimal `json:"price" comment:"委托价格"`
	PriceU        decimal.Decimal `json:"priceU" comment:"委托价格(U)"`
	FinalPrice    decimal.Decimal `json:"finalPrice" comment:"实际成交价"`
	PositionSide  string          `json:"positionSide" comment:"持仓方向 LONG-多 SHORT-空"`
	Side          string          `json:"side" comment:"买卖方向 SELL-卖 BUY-买"`
	SignPrice     decimal.Decimal `json:"signPrice" comment:"行情价"`
	TriggerTime   time.Time       `json:"triggerTime" comment:"触发时间"`
	Status        int             `json:"status" comment:"状态 1-待下单 2-已下单 3-已成交 4-已平仓 5-已止损"`
	common.ControlBy
}

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

	model.OrderSn = s.OrderSn
	model.OrderId = s.OrderId
	model.FollowOrderSn = s.FollowOrderSn
	model.Symbol = s.Symbol
	model.OrderType = s.OrderType
	model.BuyPrice = s.BuyPrice
	model.Price = s.Price
	model.PriceU = s.PriceU
	model.FinalPrice = s.FinalPrice
	model.PositionSide = s.PositionSide
	model.Side = s.Side
	model.SignPrice = s.SignPrice
	model.Status = s.Status
	model.UpdateBy = s.UpdateBy // 添加这而，需要记录是被谁更新的
}

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

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

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

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

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