package dto

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

type CarGetPageReq struct {
	dto.Pagination `search:"-"`
	Name           string `form:"name" search:"-"`                               // 车牌号
	Sn             string `form:"sn" search:"type:contains;column:sn;table:car"` // sn
	IsBind         bool   `form:"isBind" search:"-"`                             // 是否绑定司机
	CarOrder
}

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

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

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

func (s *CarInsertReq) Generate(model *model.Car) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.CarNo = s.CarNo
	model.Sn = s.Sn
	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
	}
	if s.DeptBy.DeptId != 0 {
		model.DeptId = s.DeptId
	}
}

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

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

func (s *CarUpdateReq) Generate(model *model.Car) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.CarNo = s.CarNo
	model.Sn = s.Sn
	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 *CarUpdateReq) GetId() interface{} {
	return s.Id
}

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

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

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

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