//Package po generated by 'freedom new-po'
package po

import (
	"gorm.io/gorm"
	"time"
)

// Delivery .
type Delivery struct {
	changes        map[string]interface{}
	ID             int       `gorm:"primaryKey;column:id"`
	AdminID        int       `gorm:"column:admin_id"` // 管理员id
	OrderNo        string    `gorm:"column:order_no"`
	TrackingNumber string    `gorm:"column:tracking_number"` // 快递单号
	Created        time.Time `gorm:"column:created"`
	Updated        time.Time `gorm:"column:updated"`
}

// TableName .
func (obj *Delivery) TableName() string {
	return "delivery"
}

// Location .
func (obj *Delivery) Location() map[string]interface{} {
	return map[string]interface{}{"id": obj.ID}
}

// GetChanges .
func (obj *Delivery) GetChanges() map[string]interface{} {
	if obj.changes == nil {
		return nil
	}
	result := make(map[string]interface{})
	for k, v := range obj.changes {
		result[k] = v
	}
	obj.changes = nil
	return result
}

// Update .
func (obj *Delivery) Update(name string, value interface{}) {
	if obj.changes == nil {
		obj.changes = make(map[string]interface{})
	}
	obj.changes[name] = value
}

// SetAdminID .
func (obj *Delivery) SetAdminID(adminID int) {
	obj.AdminID = adminID
	obj.Update("admin_id", adminID)
}

// SetOrderNo .
func (obj *Delivery) SetOrderNo(orderNo string) {
	obj.OrderNo = orderNo
	obj.Update("order_no", orderNo)
}

// SetTrackingNumber .
func (obj *Delivery) SetTrackingNumber(trackingNumber string) {
	obj.TrackingNumber = trackingNumber
	obj.Update("tracking_number", trackingNumber)
}

// SetCreated .
func (obj *Delivery) SetCreated(created time.Time) {
	obj.Created = created
	obj.Update("created", created)
}

// SetUpdated .
func (obj *Delivery) SetUpdated(updated time.Time) {
	obj.Updated = updated
	obj.Update("updated", updated)
}

// AddAdminID .
func (obj *Delivery) AddAdminID(adminID int) {
	obj.AdminID += adminID
	obj.Update("admin_id", gorm.Expr("admin_id + ?", adminID))
}
