60 lines
1022 B
Go
Raw Normal View History

2025-07-18 20:10:29 +07:00
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
}