package dto

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

	"github.com/shopspring/decimal"
)

type LineStrategyTemplateGetPageReq struct {
	dto.Pagination `search:"-"`
	Direction      int             `form:"direction"  search:"type:exact;column:direction;table:line_strategy_template" comment:"涨跌方向 1-涨 2-跌"`
	Percentag      decimal.Decimal `form:"percentag"  search:"type:exact;column:percentag;table:line_strategy_template" comment:"涨跌点数"`
	CompareType    int             `form:"compareType"  search:"type:exact;column:compare_type;table:line_strategy_template" comment:"比较类型 1-大于 2-大于等于 3-小于 4-小于等于 5等于 "`
	LineStrategyTemplateOrder
}

type LineStrategyTemplateOrder struct {
	Id            string `form:"idOrder"  search:"type:order;column:id;table:line_strategy_template"`
	Direction     string `form:"directionOrder"  search:"type:order;column:direction;table:line_strategy_template"`
	Percentag     string `form:"percentagOrder"  search:"type:order;column:percentag;table:line_strategy_template"`
	CompareType   string `form:"compareTypeOrder"  search:"type:order;column:compare_type;table:line_strategy_template"`
	TimeSlotStart string `form:"timeSlotStartOrder"  search:"type:order;column:time_slot_start;table:line_strategy_template"`
	TimeSlotEnd   string `form:"timeSlotEndOrder"  search:"type:order;column:time_slot_end;table:line_strategy_template"`
	CreatedAt     string `form:"createdAtOrder"  search:"type:order;column:created_at;table:line_strategy_template"`
	UpdatedAt     string `form:"updatedAtOrder"  search:"type:order;column:updated_at;table:line_strategy_template"`
	DeletedAt     string `form:"deletedAtOrder"  search:"type:order;column:deleted_at;table:line_strategy_template"`
	CreateBy      string `form:"createByOrder"  search:"type:order;column:create_by;table:line_strategy_template"`
	UpdateBy      string `form:"updateByOrder"  search:"type:order;column:update_by;table:line_strategy_template"`
}

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

type LineStrategyTemplateInsertReq struct {
	Id            int             `json:"-" comment:"主键id"` // 主键id
	Name          string          `json:"name" comment:"策略名称"`
	Direction     int             `json:"direction" comment:"涨跌方向 1-涨 2-跌"`
	Percentag     decimal.Decimal `json:"percentag" comment:"涨跌点数"`
	CompareType   int             `json:"compareType" comment:"比较类型 1-大于 2-大于等于 3-小于 4-小于等于 5等于 "`
	TimeSlotStart int             `json:"timeSlotStart" comment:"时间段开始(分)"`
	TimeSlotEnd   int             `json:"timeSlotEnd" comment:"时间断截至(分)"`
	common.ControlBy
}

// 交易参数
func (s *LineStrategyTemplateInsertReq) Valid() error {
	if s.Name == "" {
		return errors.New("策略名称不能为空")
	}
	if len(s.Name) > 50 {
		return errors.New("策略名称长度不能超过50")
	}

	if s.Percentag.Cmp(decimal.Zero) <= 0 {
		return errors.New("涨跌点数不能为空")
	}

	if s.CompareType < 1 || s.CompareType > 5 {
		return errors.New("比较类型不合法")
	}

	if s.TimeSlotStart < 0 || s.TimeSlotEnd > 59 {
		return errors.New("时间段不合法")
	}

	if s.TimeSlotEnd < s.TimeSlotStart {
		return errors.New("时间段不合法")
	}

	return nil
}

func (s *LineStrategyTemplateInsertReq) Generate(model *models.LineStrategyTemplate) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.Name = s.Name
	model.Direction = s.Direction
	model.Percentag = s.Percentag
	model.CompareType = s.CompareType
	model.TimeSlotStart = s.TimeSlotStart
	model.TimeSlotEnd = s.TimeSlotEnd
	model.CreateBy = s.CreateBy // 添加这而，需要记录是被谁创建的
}

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

type LineStrategyTemplateUpdateReq struct {
	Id            int             `uri:"id" comment:"主键id"` // 主键id
	Name          string          `json:"name" comment:"策略名称"`
	Direction     int             `json:"direction" comment:"涨跌方向 1-涨 2-跌"`
	Percentag     decimal.Decimal `json:"percentag" comment:"涨跌点数"`
	CompareType   int             `json:"compareType" comment:"比较类型 1-大于 2-大于等于 3-小于 4-小于等于 5等于 "`
	TimeSlotStart int             `json:"timeSlotStart" comment:"时间段开始(分)"`
	TimeSlotEnd   int             `json:"timeSlotEnd" comment:"时间断截至(分)"`
	common.ControlBy
}

// 交易参数
func (s *LineStrategyTemplateUpdateReq) Valid() error {
	if s.Name == "" {
		return errors.New("策略名称不能为空")
	}

	if len(s.Name) > 50 {
		return errors.New("策略名称长度不能超过50")
	}

	if s.Percentag.Cmp(decimal.Zero) <= 0 {
		return errors.New("涨跌点数不能为空")
	}

	if s.CompareType < 1 || s.CompareType > 5 {
		return errors.New("比较类型不合法")
	}

	if s.TimeSlotStart < 0 || s.TimeSlotEnd > 59 {
		return errors.New("时间段不合法")
	}

	if s.TimeSlotEnd < s.TimeSlotStart {
		return errors.New("时间段不合法")
	}

	return nil
}
func (s *LineStrategyTemplateUpdateReq) Generate(model *models.LineStrategyTemplate) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.Name = s.Name
	model.Direction = s.Direction
	model.Percentag = s.Percentag
	model.CompareType = s.CompareType
	model.TimeSlotStart = s.TimeSlotStart
	model.TimeSlotEnd = s.TimeSlotEnd
	model.UpdateBy = s.UpdateBy // 添加这而，需要记录是被谁更新的
}

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

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

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

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

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

type LineStrategyTemplateRedis struct {
	Direction     int             `json:"direction" comment:"涨跌方向 1-涨 2-跌"`
	Percentag     decimal.Decimal `json:"percentag" comment:"涨跌点数"`
	CompareType   int             `json:"compareType" comment:"比较类型 1-大于 2-大于等于 3-小于 4-小于等于 5等于 "`
	TimeSlotStart int             `json:"timeSlotStart" comment:"时间段开始(分)"`
	TimeSlotEnd   int             `json:"timeSlotEnd" comment:"时间断截至(分)"`
}
