package domain import ( "context" "fmt" "time" "gorm.io/datatypes" ) // ProductCategory defines the category of a product type ProductCategory string const ( ProductCategoryChemicals ProductCategory = "chemicals" ProductCategoryEquipment ProductCategory = "equipment" ProductCategoryMaterials ProductCategory = "materials" ProductCategoryFood ProductCategory = "food" ProductCategoryPackaging ProductCategory = "packaging" ProductCategoryOilGas ProductCategory = "oil_gas" ProductCategoryConstruction ProductCategory = "construction" ProductCategoryManufacturing ProductCategory = "manufacturing" ProductCategoryOther ProductCategory = "other" ) // Product represents a product offered by an organization (database entity) // Note: There's also a ProductJSON struct in organization.go for API serialization type Product struct { ID string `gorm:"primaryKey;type:text"` Name string `gorm:"not null;type:text;index"` Category ProductCategory `gorm:"not null;type:varchar(50);index"` Description string `gorm:"type:text"` UnitPrice float64 `gorm:"type:decimal(10,2);index"` // € per unit MOQ int `gorm:"type:integer"` // Minimum Order Quantity Certifications datatypes.JSON `gorm:"default:'[]'"` // []string // Business information OrganizationID string `gorm:"not null;type:text;index"` Organization *Organization `gorm:"foreignKey:OrganizationID"` // Additional metadata Capacity string `gorm:"type:text"` // Production capacity info Specifications datatypes.JSON `gorm:"type:jsonb;default:'{}'"` // Technical specifications Availability string `gorm:"type:text"` // Availability status Sources datatypes.JSON `gorm:"type:jsonb"` // Data sources // Timestamps CreatedAt time.Time `gorm:"autoCreateTime"` UpdatedAt time.Time `gorm:"autoUpdateTime"` } // TableName specifies the table name for GORM func (Product) TableName() string { return "products" } // ProductRepository defines operations for product management type ProductRepository interface { Create(ctx context.Context, product *Product) error GetByID(ctx context.Context, id string) (*Product, error) GetByOrganization(ctx context.Context, organizationID string) ([]*Product, error) GetByCategory(ctx context.Context, category ProductCategory) ([]*Product, error) SearchByName(ctx context.Context, name string) ([]*Product, error) GetByPriceRange(ctx context.Context, minPrice, maxPrice float64) ([]*Product, error) Update(ctx context.Context, product *Product) error Delete(ctx context.Context, id string) error GetAll(ctx context.Context) ([]*Product, error) } // Validate performs business rule validation func (p *Product) Validate() error { if p.Name == "" { return fmt.Errorf("product name cannot be empty") } if p.UnitPrice < 0 { return fmt.Errorf("unit price cannot be negative") } if p.MOQ < 0 { return fmt.Errorf("minimum order quantity cannot be negative") } return nil }