$schedule Schedule payload. * * @throws DomainException When the definition is empty. */ public function __construct( private readonly TriggerKind $kind, private readonly string $event, private readonly ?int $offset_minutes = null, private readonly ?int $skip_if_lead_time_lt_minutes = null, private readonly array $schedule = [], ) { if ( '' === trim( $this->event ) ) { throw new DomainException( 'automation.trigger_empty', 'Trigger event must not be empty.' ); } } /** * Kind. * * @since 0.1.0 */ public function kind(): TriggerKind { return $this->kind; } /** * Event or relative identifier. * * @since 0.1.0 */ public function event(): string { return $this->event; } /** * Offset minutes. * * @since 0.1.0 */ public function offset_minutes(): ?int { return $this->offset_minutes; } /** * Skip-if-too-close window. * * @since 0.1.0 */ public function skip_if_lead_time_lt_minutes(): ?int { return $this->skip_if_lead_time_lt_minutes; } /** * Schedule payload. * * @return array * * @since 0.1.0 */ public function schedule(): array { return $this->schedule; } /** * Serialise for JSON storage. * * @return array * * @since 0.1.0 */ public function to_array(): array { return [ 'kind' => $this->kind->value, 'event' => $this->event, 'offset_minutes' => $this->offset_minutes, 'skip_if_lead_time_lt_minutes' => $this->skip_if_lead_time_lt_minutes, 'schedule' => $this->schedule, ]; } /** * Hydrate from JSON. * * @param array $data Data. * * @since 0.1.0 */ public static function from_array( array $data ): self { $kind_raw = isset( $data['kind'] ) ? (string) $data['kind'] : TriggerKind::Event->value; $event = isset( $data['event'] ) ? (string) $data['event'] : ''; $offset = isset( $data['offset_minutes'] ) ? (int) $data['offset_minutes'] : null; $skip = isset( $data['skip_if_lead_time_lt_minutes'] ) ? (int) $data['skip_if_lead_time_lt_minutes'] : null; $schedule = isset( $data['schedule'] ) && is_array( $data['schedule'] ) ? $data['schedule'] : []; return new self( TriggerKind::from( $kind_raw ), $event, $offset, $skip, $schedule ); } }