package domain import ( "context" "fmt" "time" "gorm.io/datatypes" ) // UrgencyLevel defines the urgency of a service need type UrgencyLevel string const ( UrgencyLow UrgencyLevel = "low" UrgencyMedium UrgencyLevel = "medium" UrgencyHigh UrgencyLevel = "high" ) // ServiceNeed represents a service needed by an organization (database entity) // Note: There's also a ServiceNeedJSON struct in organization.go for API serialization type ServiceNeed struct { ID string `gorm:"primaryKey;type:text"` Type string `gorm:"not null;type:text;index"` // Type of service needed Description string `gorm:"type:text"` Urgency UrgencyLevel `gorm:"type:varchar(20);default:'medium'"` Budget float64 `gorm:"type:decimal(10,2)"` // Available budget in € PreferredProviders datatypes.JSON `gorm:"type:jsonb;default:'[]'"` // []string - Organization IDs // Business information OrganizationID string `gorm:"not null;type:text;index"` Organization *Organization `gorm:"foreignKey:OrganizationID"` // Additional metadata Requirements datatypes.JSON `gorm:"type:jsonb;default:'{}'"` // Specific requirements Timeframe string `gorm:"type:text"` // When service is needed Status string `gorm:"type:varchar(50);default:'active'"` // active, fulfilled, cancelled 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 (ServiceNeed) TableName() string { return "service_needs" } // ServiceNeedRepository defines operations for service need management type ServiceNeedRepository interface { Create(ctx context.Context, serviceNeed *ServiceNeed) error GetByID(ctx context.Context, id string) (*ServiceNeed, error) GetByOrganization(ctx context.Context, organizationID string) ([]*ServiceNeed, error) GetByType(ctx context.Context, serviceType string) ([]*ServiceNeed, error) GetByUrgency(ctx context.Context, urgency UrgencyLevel) ([]*ServiceNeed, error) GetActiveNeeds(ctx context.Context) ([]*ServiceNeed, error) Update(ctx context.Context, serviceNeed *ServiceNeed) error Delete(ctx context.Context, id string) error } // Validate performs business rule validation func (sn *ServiceNeed) Validate() error { if sn.Type == "" { return fmt.Errorf("service type cannot be empty") } if sn.Budget < 0 { return fmt.Errorf("budget cannot be negative") } return nil }