package dto

import (
	"cold-delivery/app/admin/model"
	"cold-delivery/common/dto"
	common "cold-delivery/common/model"
	"strings"
)

type CoolerBoxGetPageReq struct {
	dto.Pagination `search:"-"`
	Name           string `form:"name" search:"type:contains;column:name;table:cooler_box"`  // 保温箱
	Sn             string `form:"sn" search:"type:contains;column:sn;table:cooler_box"`      // sn
	Status         string `form:"status" search:"type:exact;column:status;table:cooler_box"` // 状态
	ShowTemp       bool   `form:"showTemp" search:"-"`                                       // 展示最新温度
	CoolerBoxOrder
}

type CoolerBoxOrder struct {
	CreatedAtOrder string `search:"type:order;column:created_at;table:cooler_box" form:"createdAtOrder" default:"desc"`
}

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

type CoolerBoxInsertReq struct {
	Id               int    `json:"id" comment:"编码" swaggerignore:"true"` // 编码
	Name             string `json:"name"`                                 // 保温箱名称
	Sn               string `json:"sn"`                                   // sn
	Status           string `json:"status"`                               // 1-停用 2-正常
	common.ControlBy `swaggerignore:"true"`
	common.DeptBy    `swaggerignore:"true"`
}

func (s *CoolerBoxInsertReq) Generate(model *model.CoolerBox) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.Name = s.Name
	model.Sn = strings.TrimSpace(s.Sn)
	model.Status = s.Status
	if s.ControlBy.UpdateBy != 0 {
		model.UpdateBy = s.UpdateBy
	}
	if s.ControlBy.CreateBy != 0 {
		model.CreateBy = s.CreateBy
	}
	if s.DeptBy.DeptId != 0 {
		model.DeptId = s.DeptId
	}
}

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

type CoolerBoxUpdateReq struct {
	Id               int    `json:"id" comment:"编码"` // 编码
	Name             string `json:"name"`            // 保温箱名称
	Sn               string `json:"sn"`              // sn
	Status           string `json:"status"`          // 1-停用 2-正常
	common.ControlBy `swaggerignore:"true"`
}

func (s *CoolerBoxUpdateReq) Generate(model *model.CoolerBox) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.Name = s.Name
	model.Sn = strings.TrimSpace(s.Sn)
	model.Status = s.Status
	if s.ControlBy.UpdateBy != 0 {
		model.UpdateBy = s.UpdateBy
	}
	if s.ControlBy.CreateBy != 0 {
		model.CreateBy = s.CreateBy
	}
}

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

type CoolerBoxGetReq struct {
	Id int `uri:"id"`
}

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

type CoolerBoxDeleteReq struct {
	Id               int `json:"id"`
	common.ControlBy `swaggerignore:"true"`
}

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

type CoolerBoxBatchInsertReq struct {
	List             []CoolerBoxInsertReq
	Status           string `json:"status"` // 1-停用 2-正常
	common.ControlBy `swaggerignore:"true"`
	common.DeptBy    `swaggerignore:"true"`
}
