60 lines
1022 B
Go
60 lines
1022 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type Inventory struct {
|
|
ID uuid.UUID
|
|
OutletID uuid.UUID
|
|
ProductID uuid.UUID
|
|
Quantity int
|
|
ReorderLevel int
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
type CreateInventoryRequest struct {
|
|
OutletID uuid.UUID
|
|
ProductID uuid.UUID
|
|
Quantity int
|
|
ReorderLevel int
|
|
}
|
|
|
|
type UpdateInventoryRequest struct {
|
|
Quantity *int
|
|
ReorderLevel *int
|
|
}
|
|
|
|
type InventoryAdjustmentRequest struct {
|
|
Delta int
|
|
Reason string
|
|
}
|
|
|
|
type InventoryResponse struct {
|
|
ID uuid.UUID
|
|
OutletID uuid.UUID
|
|
ProductID uuid.UUID
|
|
Quantity int
|
|
ReorderLevel int
|
|
IsLowStock bool
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
func (i *Inventory) IsLowStock() bool {
|
|
return i.Quantity <= i.ReorderLevel
|
|
}
|
|
|
|
func (i *Inventory) CanFulfillOrder(requestedQuantity int) bool {
|
|
return i.Quantity >= requestedQuantity
|
|
}
|
|
|
|
func (i *Inventory) AdjustQuantity(delta int) int {
|
|
newQuantity := i.Quantity + delta
|
|
if newQuantity < 0 {
|
|
newQuantity = 0
|
|
}
|
|
return newQuantity
|
|
}
|