package dto

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

type WarehouseGetPageReq struct {
	dto.Pagination `search:"-"`
	//Code           string `form:"name" search:"type:contains;column:name;table:warehouse"` // 仓库名称
	Name   string `form:"name" search:"-"`                                     // 仓库名称
	Sn     string `form:"sn" search:"type:contains;column:sn;table:warehouse"` // sn
	IsBind bool   `form:"isBind" search:"-"`                                   // 是否绑定司机
	WarehouseOrder
}

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

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

type WarehouseInsertReq struct {
	Id               int    `json:"id" comment:"编码" swaggerignore:"true"` // 编码
	Name             string `json:"name"`                                 // 商品名称
	Sn               string `json:"sn"`                                   // sn
	Address          string `json:"address"`                              // 地址
	Status           string `json:"status"`                               // 1-停用 2-正常
	UserId           int    `json:"userId"`                               // 绑定的用户id
	common.ControlBy `swaggerignore:"true"`
	common.DeptBy    `swaggerignore:"true"`
}

func (s *WarehouseInsertReq) Generate(model *model.Warehouse) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.Name = s.Name
	model.Sn = s.Sn
	model.Status = s.Status
	model.Address = s.Address
	model.UserId = s.UserId
	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 *WarehouseInsertReq) GetId() interface{} {
	return s.Id
}

type WarehouseUpdateReq struct {
	Id               int    `json:"id" comment:"编码"` // 编码
	Name             string `json:"name"`            // 商品名称
	Sn               string `json:"sn"`              // sn
	Address          string `json:"address"`         // 地址
	Status           string `json:"status"`          // 1-停用 2-正常
	UserId           int    `json:"userId"`          // 绑定的用户id
	common.ControlBy `swaggerignore:"true"`
}

func (s *WarehouseUpdateReq) Generate(model *model.Warehouse) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.Name = s.Name
	model.Sn = s.Sn
	model.Address = s.Address
	model.Status = s.Status
	model.UserId = s.UserId
	if s.ControlBy.UpdateBy != 0 {
		model.UpdateBy = s.UpdateBy
	}
	if s.ControlBy.CreateBy != 0 {
		model.CreateBy = s.CreateBy
	}
}

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

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

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

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

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