|null $target_ids Target entity ids. * @param list|null $booking_statuses Status allow-list. * @param bool $is_enabled Enabled. * @param DateTimeImmutable $created_at Created. * @param DateTimeImmutable $updated_at Updated. */ public function __construct( private ?int $id, private readonly Uuid $uuid, private readonly string $name, private readonly string $template_key, private readonly string $channel, private readonly int $offset_minutes, private readonly string $applies_to, private readonly ?array $target_ids, private readonly ?array $booking_statuses, private readonly bool $is_enabled, private readonly DateTimeImmutable $created_at, private readonly DateTimeImmutable $updated_at, ) {} /** * Id. * * @since 0.1.0 */ public function id(): ?int { return $this->id; } /** * Assign id. * * @param int $id Id. * * @since 0.1.0 */ public function assign_id( int $id ): void { $this->id = $id; } /** * Uuid. * * @since 0.1.0 */ public function uuid(): Uuid { return $this->uuid; } /** * Name. * * @since 0.1.0 */ public function name(): string { return $this->name; } /** * Template key. * * @since 0.1.0 */ public function template_key(): string { return $this->template_key; } /** * Channel. * * @since 0.1.0 */ public function channel(): string { return $this->channel; } /** * Offset minutes. * * @since 0.1.0 */ public function offset_minutes(): int { return $this->offset_minutes; } /** * Applies to. * * @since 0.1.0 */ public function applies_to(): string { return $this->applies_to; } /** * Target ids. * * @return list|null * * @since 0.1.0 */ public function target_ids(): ?array { return $this->target_ids; } /** * Booking statuses. * * @return list|null * * @since 0.1.0 */ public function booking_statuses(): ?array { return $this->booking_statuses; } /** * Is enabled. * * @since 0.1.0 */ public function is_enabled(): bool { return $this->is_enabled; } /** * Created at. * * @since 0.1.0 */ public function created_at(): DateTimeImmutable { return $this->created_at; } /** * Updated at. * * @since 0.1.0 */ public function updated_at(): DateTimeImmutable { return $this->updated_at; } /** * Whether this rule applies to a booking snapshot. * * @param string $status Booking status value. * @param int $service_id Service id. * @param int|null $agent_id Agent id. * @param int|null $location_id Location id. * * @since 0.1.0 */ public function matches( string $status, int $service_id, ?int $agent_id, ?int $location_id ): bool { if ( ! $this->is_enabled ) { return false; } $statuses = $this->booking_statuses ?? [ 'approved', 'confirmed' ]; if ( ! in_array( $status, $statuses, true ) ) { return false; } return match ( $this->applies_to ) { 'all' => true, 'service' => null !== $this->target_ids && in_array( $service_id, $this->target_ids, true ), 'agent' => null !== $agent_id && null !== $this->target_ids && in_array( $agent_id, $this->target_ids, true ), 'location' => null !== $location_id && null !== $this->target_ids && in_array( $location_id, $this->target_ids, true ), default => false, }; } }