package models

import (
	"time"
)

type Tripsheet struct {
	Tripsheetid      int        `json:"tripsheetid" gorm:"primaryKey;column:tripsheetid"`
	Tripsheetno      string     `json:"tripsheetno" gorm:"column:tripsheetno;unique;not null"`
	Sourcehubid      int        `json:"sourcehubid" gorm:"column:sourcehubid;not null"`
	Destinationhubid int        `json:"destinationhubid" gorm:"column:destinationhubid;not null"`
	Vehicleid        *int       `json:"vehicleid" gorm:"column:vehicleid"`
	Driveruserid     *int       `json:"driveruserid" gorm:"column:driveruserid"`
	Dispatchtime     *time.Time `json:"dispatchtime" gorm:"column:dispatchtime"`
	Arrivaltime      *time.Time `json:"arrivaltime" gorm:"column:arrivaltime"`
	Status           string     `json:"status" gorm:"column:status;default:Draft"` // Draft, Ready, Dispatched, Arrived, Cancelled
	Batchlabel       string     `json:"batchlabel" gorm:"column:batchlabel;size:100"`
	Batchkind        string     `json:"batchkind" gorm:"column:batchkind;size:20"` // local, transfer
	Destinationlabel string     `json:"destinationlabel" gorm:"column:destinationlabel;size:200"`
	Createdat        time.Time  `json:"createdat" gorm:"column:createdat;default:CURRENT_TIMESTAMP"`
	Updatedat        time.Time  `json:"updatedat" gorm:"column:updatedat;default:CURRENT_TIMESTAMP"`
	Createdby        int        `json:"createdby" gorm:"column:createdby"`
	Updatedby        int        `json:"updatedby" gorm:"column:updatedby"`
	Deletedat        *time.Time `json:"deletedat,omitempty" gorm:"column:deletedat"`
}

func (Tripsheet) TableName() string {
	return "tripsheets"
}

type TripsheetItem struct {
	Tripsheetitemid int        `json:"tripsheetitemid" gorm:"primaryKey;column:tripsheetitemid"`
	Tripsheetid     int        `json:"tripsheetid" gorm:"column:tripsheetid;not null"`
	Consignmentid   int        `json:"consignmentid" gorm:"column:consignmentid;not null"`
	Scanstatus      string     `json:"scanstatus" gorm:"column:scanstatus;default:Pending"` // Pending, Loaded, Unloaded, Discrepancy
	Scannedat       *time.Time `json:"scannedat" gorm:"column:scannedat"`
	Createdat       time.Time  `json:"createdat" gorm:"column:createdat;default:CURRENT_TIMESTAMP"`
	Updatedat       time.Time  `json:"updatedat" gorm:"column:updatedat;default:CURRENT_TIMESTAMP"`
	Createdby       int        `json:"createdby" gorm:"column:createdby"`
	Updatedby       int        `json:"updatedby" gorm:"column:updatedby"`
	Deletedat       *time.Time `json:"deletedat,omitempty" gorm:"column:deletedat"`
}

func (TripsheetItem) TableName() string {
	return "tripsheetitems"
}

type DeliveryProof struct {
	Proofid              int       `json:"proofid" gorm:"primaryKey;column:proofid"`
	Consignmentid        int       `json:"consignmentid" gorm:"column:consignmentid;unique;not null"`
	Tripsheetid          *int      `json:"tripsheetid" gorm:"column:tripsheetid"`
	Deliveredat          time.Time `json:"deliveredat" gorm:"column:deliveredat;not null"`
	Deliveredtoname      string    `json:"deliveredtoname" gorm:"column:deliveredtoname;not null"`
	Receiversignatureurl string    `json:"receiversignatureurl" gorm:"column:receiversignatureurl"`
	Photourl             string    `json:"photourl" gorm:"column:photourl"`
	Otpverified          bool      `json:"otpverified" gorm:"column:otpverified;default:false"`
	Geolatitude          float64   `json:"geolatitude" gorm:"column:geolatitude"`
	Geolongitude         float64   `json:"geolongitude" gorm:"column:geolongitude"`
	Createdat            time.Time `json:"createdat" gorm:"column:createdat;default:CURRENT_TIMESTAMP"`
	Createdby            int       `json:"createdby" gorm:"column:createdby"`
}

func (DeliveryProof) TableName() string {
	return "deliveryproofs"
}
