package repository import ( "context" "bugulma/backend/internal/domain" "gorm.io/gorm" ) // SharedAssetRepository implements domain.SharedAssetRepository with GORM type SharedAssetRepository struct { *BaseRepository[domain.SharedAsset] } // NewSharedAssetRepository creates a new GORM-based shared asset repository func NewSharedAssetRepository(db *gorm.DB) domain.SharedAssetRepository { return &SharedAssetRepository{ BaseRepository: NewBaseRepository[domain.SharedAsset](db), } } // GetBySiteID retrieves shared assets at a specific site func (r *SharedAssetRepository) GetBySiteID(ctx context.Context, siteID string) ([]*domain.SharedAsset, error) { return r.FindWhereWithContext(ctx, "site_id = ?", siteID) } // GetByOwnerID retrieves shared assets owned by a specific organization func (r *SharedAssetRepository) GetByOwnerID(ctx context.Context, ownerID string) ([]*domain.SharedAsset, error) { return r.FindWhereWithContext(ctx, "owner_organization_id = ?", ownerID) } // GetByType retrieves shared assets by type func (r *SharedAssetRepository) GetByType(ctx context.Context, assetType domain.AssetType) ([]*domain.SharedAsset, error) { return r.FindWhereWithContext(ctx, "type = ?", assetType) } // GetAvailable retrieves assets with available capacity (utilization < 1.0) func (r *SharedAssetRepository) GetAvailable(ctx context.Context) ([]*domain.SharedAsset, error) { return r.FindWhereWithContext(ctx, "utilization_rate < ? AND operational_status = ?", 1.0, domain.StatusOperational) }