package model

import (
	model2 "cold-delivery/common/model"
	"database/sql/driver"
	"encoding/json"
)

var (
	WaybillStatusWaitDelivery = 1 // 已下单
	WaybillStatusInDelivery   = 2 // 配送中

	WaybillStatusReceipt   = 3 // 已签收
	WaybillStatusRejection = 4 // 已拒收
	WaybillStatusMap       = map[int]string{
		WaybillStatusWaitDelivery: "已下单",
		WaybillStatusInDelivery:   "配送中",
		WaybillStatusReceipt:      "已签收",
		WaybillStatusRejection:    "已拒收",
	}
)

// 运单短信发送日志
type WaybillSendLog struct {
	Phone   string `json:"phone"`
	Content string `json:"content"`
}

func (e WaybillSendLog) Value() (driver.Value, error) {
	d, err := json.Marshal(e)
	return string(d), err
}
func (e *WaybillSendLog) Scan(src interface{}) error {
	return json.Unmarshal(src.([]byte), e)
}

type IceRaftCode []string

func (e IceRaftCode) Value() (driver.Value, error) {
	d, err := json.Marshal(e)
	return string(d), err
}

func (e *IceRaftCode) Scan(src interface{}) error {
	return json.Unmarshal(src.([]byte), e)
}

// 运单
type Waybill struct {
	model2.Model
	WaybillNo               string         `json:"waybillNo"  gorm:"size:128"`                    // 单号
	OrderNo                 string         `json:"orderNo"  gorm:"size:128"`                      // 订单号
	Status                  int            `json:"status"  gorm:"size:128"`                       // 订单状态：1已下单 2配送中 3已送达 4已拒收
	SenderAddressDetails    string         `json:"senderAddressDetails"  gorm:"size:128"`         // 发货地址详情
	SenderAddressName       string         `json:"senderAddressName"  gorm:"size:128"`            // 发货地址名称
	SenderAddressPhone      string         `json:"senderAddressPhone"  gorm:"size:128"`           // 发货地址电话
	ConsigneeAddressDetails string         `json:"consigneeAddressDetails"  gorm:"size:128"`      // 收发货地址详情
	ConsigneeAddressName    string         `json:"consigneeAddressName"  gorm:"size:128"`         // 收发货地址名称
	ConsigneeAddressPhone   string         `json:"consigneeAddressPhone"  gorm:"size:128"`        // 收发货地址电话
	DeliveryName            string         `json:"deliveryName"  gorm:"size:128"`                 // 配送人名称
	DeliveryPhone           string         `json:"deliveryPhone"  gorm:"size:128"`                // 配送人电话
	DeliveryId              int            `json:"deliveryId"  gorm:"size:128"`                   // 配送人id
	ReCheckId               int            `json:"reCheckId"  gorm:"size:128"`                    // 复核id
	Remark                  string         `json:"remark"  gorm:"size:text"`                      // 运输备注
	OrderTime               model2.Time    `json:"orderTime"  gorm:"size:128"`                    // 下单时间
	DeliveryTime            model2.Time    `json:"deliveryTime"  gorm:"size:128"`                 // 配送时间
	DeliveryDuration        int            `json:"deliveryDuration" gorm:"size:128;comment:冷冻时长"` // 配送耗时 单位分钟
	ReceiptTime             model2.Time    `json:"receiptTime"  gorm:"size:128"`                  // 签收时间
	Quantity                int            `json:"quantity"  gorm:"size:128"`                     // 药品数量
	CoolerBoxId             int            `json:"coolerBoxId"  gorm:"size:128"`                  // 保温箱id
	ReceiptImg              string         `json:"receiptImg"  gorm:"size:text"`                  // 签收图片
	TamperProofLabel        string         `json:"tamperProofLabel"  gorm:"size:128"`             // 防拆标签
	TamperProofLabelImg     string         `json:"tamperProofLabelImg"  gorm:"size:text"`         // 防拆标签
	RejectionReason         string         `json:"rejectionReason"  gorm:"size:128"`              // 拒收原因
	SendLog                 WaybillSendLog `json:"sendLog" gorm:"size:text"`                      // 运单短信发送日志
	CoolerBox               CoolerBoxOmit  `json:"coolerBox" gorm:"->"`                           // 保温箱
	Dept                    SysDeptOmit    `json:"dept" gorm:"->"`                                // 部门
	Delivery                SysUserOmit    `json:"delivery" gorm:"->"`                            // 部门
	ReCheck                 SysUserOmit    `json:"reCheck" gorm:"->"`                             // 部门
	IceRaftCode             IceRaftCode    `json:"iceRaftCode" gorm:"size:text"`
	AssessStar              int            `json:"assessStar"  gorm:"size:128"`    // 评价星星
	AssessContent           string         `json:"assessContent"  gorm:"size:128"` // 评价内容
	model2.ControlBy
	model2.ModelTime
	model2.DeptBy
}

func (Waybill) TableName() string {
	return "waybill"
}
