id; } /** * Ceiling for a dimension. 0 means unlimited. * * @param EditionDimension $dimension Dimension. */ public function max( EditionDimension $dimension ): int { return match ( $dimension ) { EditionDimension::Service => $this->max_services, EditionDimension::Agent => $this->max_agents, EditionDimension::Location => $this->max_locations, EditionDimension::BookingForm => $this->max_booking_forms, }; } /** * Whether another row may be created. * * @param EditionDimension $dimension Dimension. * @param int $current_count Non-deleted rows already stored. */ public function allows_another( EditionDimension $dimension, int $current_count ): bool { $max = $this->max( $dimension ); if ( $max < 1 ) { return true; } return $current_count < $max; } /** * Clamp a desired seed/target count to this edition. * * @param EditionDimension $dimension Dimension. * @param int $desired Requested count. */ public function cap( EditionDimension $dimension, int $desired ): int { $max = $this->max( $dimension ); if ( $max < 1 ) { return max( 0, $desired ); } return max( 0, min( $desired, $max ) ); } /** * Public payload for the admin SPA. 0 means unlimited. * * @return array{id: string, services: int, agents: int, locations: int, bookingForms: int} */ public function to_public_array(): array { return [ 'id' => $this->id, 'services' => $this->max_services, 'agents' => $this->max_agents, 'locations' => $this->max_locations, 'bookingForms' => $this->max_booking_forms, ]; } }