package entities

import (
	"time"

	"gorm.io/gorm"
)

const (
	StockAllocationStatusPending  = "PENDING"
	StockAllocationStatusActive   = "ACTIVE"
	StockAllocationStatusReleased = "RELEASED"

	StockAllocationPurposeConsume      = "CONSUME"
	StockAllocationPurposeTraceChickin = "TRACE_CHICKIN"
)

// StockAllocation links a usable record (consumption) with an incoming stock record.
// The combination lets us trace FIFO deductions while keeping each module focused on its own fields.
type StockAllocation struct {
	Id                 uint           `gorm:"primaryKey"`
	ProductWarehouseId uint           `gorm:"not null;index"`
	StockableType      string         `gorm:"size:100;not null;index:stock_allocations_lookup,priority:1"`
	StockableId        uint           `gorm:"not null;index:stock_allocations_lookup,priority:2"`
	UsableType         string         `gorm:"size:100;not null;index:stock_allocations_usage_lookup,priority:1"`
	UsableId           uint           `gorm:"not null;index:stock_allocations_usage_lookup,priority:2"`
	Qty                float64        `gorm:"type:numeric(15,3);not null"`
	AllocationPurpose  string         `gorm:"size:32;not null;default:CONSUME;index:stock_allocations_purpose_status,priority:1"`
	Status             string         `gorm:"size:20;not null;default:ACTIVE;index:stock_allocations_purpose_status,priority:2"`
	Note               *string        `gorm:"type:text"`
	CreatedAt          time.Time      `gorm:"autoCreateTime"`
	UpdatedAt          time.Time      `gorm:"autoUpdateTime"`
	ReleasedAt         *time.Time     `gorm:"index"`
	DeletedAt          gorm.DeletedAt `gorm:"index"`

	ProductWarehouse *ProductWarehouse `gorm:"foreignKey:ProductWarehouseId;references:Id"`
}
