package domain import ( "context" "fmt" "time" "gorm.io/datatypes" ) // ServiceType defines the type of service type ServiceType string const ( ServiceTypeMaintenance ServiceType = "maintenance" ServiceTypeConsulting ServiceType = "consulting" ServiceTypeTransport ServiceType = "transport" ServiceTypeInspection ServiceType = "inspection" ServiceTypeTraining ServiceType = "training" ServiceTypeRepair ServiceType = "repair" ServiceTypeOther ServiceType = "other" ) // Service represents a service offered by an organization (database entity) // Note: There's also a ServiceJSON struct in organization.go for API serialization type Service struct { ID string `gorm:"primaryKey;type:text"` Type ServiceType `gorm:"not null;type:varchar(50);index"` Domain string `gorm:"not null;type:text;index"` // Service domain (compressors, HVAC, etc.) Description string `gorm:"type:text"` OnSite bool `gorm:"not null;default:false"` // Whether service is performed on-site HourlyRate float64 `gorm:"type:decimal(10,2)"` // € per hour ServiceAreaKm float64 `gorm:"type:decimal(8,2)"` // Service area radius in km Certifications datatypes.JSON `gorm:"default:'[]'"` // []string // Business information OrganizationID string `gorm:"not null;type:text;index"` Organization *Organization `gorm:"foreignKey:OrganizationID"` // Additional metadata ResponseTime string `gorm:"type:text"` // Response time SLA Warranty string `gorm:"type:text"` // Warranty terms Specializations datatypes.JSON `gorm:"type:jsonb;default:'[]'"` // []string - specific specializations Availability string `gorm:"type:text"` // Service availability 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 (Service) TableName() string { return "services" } // ServiceRepository defines operations for service management type ServiceRepository interface { Create(ctx context.Context, service *Service) error GetByID(ctx context.Context, id string) (*Service, error) GetByOrganization(ctx context.Context, organizationID string) ([]*Service, error) GetByType(ctx context.Context, serviceType ServiceType) ([]*Service, error) GetByDomain(ctx context.Context, domain string) ([]*Service, error) SearchByDescription(ctx context.Context, description string) ([]*Service, error) GetByServiceArea(ctx context.Context, lat, lng, radiusKm float64) ([]*Service, error) Update(ctx context.Context, service *Service) error Delete(ctx context.Context, id string) error GetAll(ctx context.Context) ([]*Service, error) } // Validate performs business rule validation func (s *Service) Validate() error { if s.Domain == "" { return fmt.Errorf("service domain cannot be empty") } if s.HourlyRate < 0 { return fmt.Errorf("hourly rate cannot be negative") } if s.ServiceAreaKm < 0 { return fmt.Errorf("service area cannot be negative") } return nil }