$config Action config. * @param int $delay_minutes Delay before execute. * @param int $sort_order Order. * @param ContextMode $context_mode Snapshot or fresh. * @param AutomationRecipient|null $recipient Required on send actions. * @param SendIntent|null $intent Required on send actions. * * @throws DomainException When type is empty. */ public function __construct( private readonly string $type, private readonly array $config, private readonly int $delay_minutes, private readonly int $sort_order, private readonly ContextMode $context_mode, private readonly ?AutomationRecipient $recipient = null, private readonly ?SendIntent $intent = null, ) { if ( '' === trim( $this->type ) ) { throw new DomainException( 'automation.action_type_empty', 'Action type must not be empty.' ); } if ( $this->delay_minutes < 0 ) { throw new DomainException( 'automation.delay_negative', 'Delay must not be negative.' ); } } /** * Type. * * @since 0.1.0 */ public function type(): string { return $this->type; } /** * Config. * * @return array * * @since 0.1.0 */ public function config(): array { return $this->config; } /** * Delay minutes. * * @since 0.1.0 */ public function delay_minutes(): int { return $this->delay_minutes; } /** * Sort order. * * @since 0.1.0 */ public function sort_order(): int { return $this->sort_order; } /** * Context mode. * * @since 0.1.0 */ public function context_mode(): ContextMode { return $this->context_mode; } /** * Recipient. * * @since 0.1.0 */ public function recipient(): ?AutomationRecipient { return $this->recipient; } /** * Intent. * * @since 0.1.0 */ public function intent(): ?SendIntent { return $this->intent; } /** * Serialise. * * @return array * * @since 0.1.0 */ public function to_array(): array { return [ 'type' => $this->type, 'config' => $this->config, 'delay_minutes' => $this->delay_minutes, 'sort_order' => $this->sort_order, 'context_mode' => $this->context_mode->value, 'recipient' => $this->recipient?->value, 'intent' => $this->intent?->value, ]; } /** * Hydrate. * * @param array $data Data. * * @since 0.1.0 */ public static function from_array( array $data ): self { $config = isset( $data['config'] ) && is_array( $data['config'] ) ? $data['config'] : []; $mode = isset( $data['context_mode'] ) ? (string) $data['context_mode'] : ContextMode::Snapshot->value; $recip = isset( $data['recipient'] ) && is_string( $data['recipient'] ) && '' !== $data['recipient'] ? AutomationRecipient::from( $data['recipient'] ) : null; $intent = isset( $data['intent'] ) && is_string( $data['intent'] ) && '' !== $data['intent'] ? SendIntent::from( $data['intent'] ) : null; return new self( (string) ( $data['type'] ?? '' ), $config, (int) ( $data['delay_minutes'] ?? 0 ), (int) ( $data['sort_order'] ?? 0 ), ContextMode::from( $mode ), $recip, $intent ); } }