package dto

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

	"github.com/shopspring/decimal"
)

type LinePreOrderExtGetPageReq struct {
	dto.Pagination `search:"-"`
	LinePreOrderExtOrder
}

type LinePreOrderExtOrder struct {
	Id                    string `form:"idOrder"  search:"type:order;column:id;table:line_pre_order_ext"`
	MainOrderId           string `form:"mainOrderIdOrder"  search:"type:order;column:main_order_id;table:line_pre_order_ext"`
	OrderId               string `form:"orderIdOrder"  search:"type:order;column:order_id;table:line_pre_order_ext"`
	TakeProfitRatio       string `form:"takeProfitRatioOrder"  search:"type:order;column:take_profit_ratio;table:line_pre_order_ext"`
	ReducePriceRatio      string `form:"reducePriceRatioOrder"  search:"type:order;column:reduce_price_ratio;table:line_pre_order_ext"`
	ReduceNumRatio        string `form:"reduceNumRatioOrder"  search:"type:order;column:reduce_num_ratio;table:line_pre_order_ext"`
	ReduceTakeProfitRatio string `form:"reduceTakeProfitRatioOrder"  search:"type:order;column:reduce_take_profit_ratio;table:line_pre_order_ext"`
	ReduceStopLossRatio   string `form:"reduceStopLossRatioOrder"  search:"type:order;column:reduce_stop_loss_ratio;table:line_pre_order_ext"`
	AddPositionPriceRatio string `form:"addPositionPriceRatioOrder"  search:"type:order;column:add_position_price_ratio;table:line_pre_order_ext"`
	AddPositionType       string `form:"addPositionTypeOrder"  search:"type:order;column:add_position_type;table:line_pre_order_ext"`
	AddPositionVal        string `form:"addPositionValOrder"  search:"type:order;column:add_position_val;table:line_pre_order_ext"`
	CreatedAt             string `form:"createdAtOrder"  search:"type:order;column:created_at;table:line_pre_order_ext"`
	UpdatedAt             string `form:"updatedAtOrder"  search:"type:order;column:updated_at;table:line_pre_order_ext"`
	DeletedAt             string `form:"deletedAtOrder"  search:"type:order;column:deleted_at;table:line_pre_order_ext"`
	CreateBy              string `form:"createByOrder"  search:"type:order;column:create_by;table:line_pre_order_ext"`
	UpdateBy              string `form:"updateByOrder"  search:"type:order;column:update_by;table:line_pre_order_ext"`
}

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

type LineAddPreOrderExtReq struct {
	AddType            int             `json:"addType" comment:"类型 1-加仓 2-减仓"`
	OrderType          string          `json:"orderType" comment:"订单类型 LIMIT-限价 MARKET-市价"`
	PriceRatio         decimal.Decimal `json:"priceRatio" comment:"价格百分比"`
	AddPositionType    int             `json:"addPositionType" comment:"加仓类型 1-百分比 2-实际金额"`
	AddPositionVal     decimal.Decimal `json:"addPositionVal" comment:"加仓值"`
	TakeProfitRatio    decimal.Decimal `json:"takeProfitRatio" comment:"止盈百分比"`
	StopLossRatio      decimal.Decimal `json:"stopLossRatio" comment:"止损百分比"`
	TakeProfitNumRatio decimal.Decimal `json:"takeProfitNumRatio" comment:"止盈数量百分比"`
	TpTpPriceRatio     decimal.Decimal `json:"tpTpPriceRatio" comment:"止盈后止盈价格百分比"`
	TpSlPriceRatio     decimal.Decimal `json:"tpSlPriceRatio" comment:"止盈后止损价格百分比"`
	ReTakeProfitRatio  decimal.Decimal `json:"reTakeProfitRatio" comment:"亏损回本止盈百分比"`
	ExpirateHour       int             `json:"expirateHour" comment:"过期时间小时"`
}

type LinePreOrderExtInsertReq struct {
	Id                 int             `json:"-" comment:"主键id"` // 主键id
	MainOrderId        int             `json:"mainOrderId" comment:"主单id"`
	OrderId            int             `json:"orderId" comment:"订单id"`
	AddType            int             `json:"addType" comment:"类型 1-加仓 2-减仓"`
	OrderType          string          `json:"orderType" comment:"类型 LIMIT-限价 MARKET-市价"`
	PriceRatio         decimal.Decimal `json:"priceRatio" comment:"价格百分比"`
	TakeProfitRatio    decimal.Decimal `json:"takeProfitRatio" comment:"止盈百分比"`
	TakeProfitNumRatio decimal.Decimal `json:"takeProfitNumRatio" comment:"止盈数量百分比"`
	TpTpPriceRatio     decimal.Decimal `json:"tpTpPriceRatio" comment:"止盈后止盈价格百分比"`
	TpSlPriceRatio     decimal.Decimal `json:"tpSlPriceRatio" comment:"止盈后止损价格百分比"`
	AddPositionType    int             `json:"addPositionType" comment:"加仓类型 1-百分比 2-实际金额"`
	AddPositionVal     decimal.Decimal `json:"addPositionVal" comment:"加仓值"`
	common.ControlBy
}

func (s *LinePreOrderExtInsertReq) Generate(model *models.LinePreOrderExt) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.MainOrderId = s.MainOrderId
	model.OrderId = s.OrderId
	model.TakeProfitRatio = s.TakeProfitRatio
	model.AddType = s.AddType
	model.OrderType = s.OrderType
	model.PriceRatio = s.PriceRatio
	model.TpSlPriceRatio = s.TpSlPriceRatio
	model.TpSlPriceRatio = s.TpSlPriceRatio
	model.AddPositionType = s.AddPositionType
	model.AddPositionVal = s.AddPositionVal
	model.CreateBy = s.CreateBy // 添加这而，需要记录是被谁创建的
}

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

type LinePreOrderExtUpdateReq struct {
	Id                 int             `uri:"id" comment:"主键id"` // 主键id
	MainOrderId        int             `json:"mainOrderId" comment:"主单id"`
	OrderId            int             `json:"orderId" comment:"订单id"`
	AddType            int             `json:"addType" comment:"类型 1-加仓 2-减仓"`
	OrderType          string          `json:"orderType" comment:"类型 LIMIT-限价 MARKET-市价"`
	PriceRatio         decimal.Decimal `json:"priceRatio" comment:"价格百分比"`
	TakeProfitRatio    decimal.Decimal `json:"takeProfitRatio" comment:"止盈百分比"`
	TakeProfitNumRatio decimal.Decimal `json:"takeProfitNumRatio" comment:"止盈数量百分比"`
	TpTpPriceRatio     decimal.Decimal `json:"tpTpPriceRatio" comment:"止盈后止盈价格百分比"`
	TpSlPriceRatio     decimal.Decimal `json:"tpSlPriceRatio" comment:"止盈后止损价格百分比"`
	AddPositionType    int             `json:"addPositionType" comment:"加仓类型 1-百分比 2-实际金额"`
	AddPositionVal     decimal.Decimal `json:"addPositionVal" comment:"加仓值"`
	common.ControlBy
}

func (s *LinePreOrderExtUpdateReq) Generate(model *models.LinePreOrderExt) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.MainOrderId = s.MainOrderId
	model.OrderId = s.OrderId
	model.TakeProfitRatio = s.TakeProfitRatio
	model.AddType = s.AddType
	model.OrderType = s.OrderType
	model.PriceRatio = s.PriceRatio
	model.TpSlPriceRatio = s.TpSlPriceRatio
	model.TpSlPriceRatio = s.TpSlPriceRatio
	model.AddPositionType = s.AddPositionType
	model.AddPositionVal = s.AddPositionVal
	model.UpdateBy = s.UpdateBy // 添加这而，需要记录是被谁更新的
}

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

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

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

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

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