$custom_fields Custom fields. * @param string|null $notes Notes. */ public function __construct( private readonly ?string $first_name = null, private readonly ?string $last_name = null, private readonly ?string $email = null, private readonly ?string $phone = null, private readonly bool $marketing_consent = false, private readonly bool $terms_accepted = false, private readonly array $custom_fields = [], private readonly ?string $notes = null, ) {} /** * Empty draft. */ public static function empty(): self { return new self(); } /** * Hydrate from stored JSON. * * @param array|null $data Stored draft. */ public static function from_array( ?array $data ): self { if ( null === $data ) { return self::empty(); } $custom = $data['custom_fields'] ?? []; return new self( isset( $data['first_name'] ) && is_string( $data['first_name'] ) ? $data['first_name'] : null, isset( $data['last_name'] ) && is_string( $data['last_name'] ) ? $data['last_name'] : null, isset( $data['email'] ) && is_string( $data['email'] ) ? $data['email'] : null, isset( $data['phone'] ) && is_string( $data['phone'] ) ? $data['phone'] : null, isset( $data['marketing_consent'] ) && true === $data['marketing_consent'], isset( $data['terms_accepted'] ) && true === $data['terms_accepted'], is_array( $custom ) ? $custom : [], isset( $data['notes'] ) && is_string( $data['notes'] ) ? $data['notes'] : null, ); } /** * First name. */ public function first_name(): ?string { return $this->first_name; } /** * Last name. */ public function last_name(): ?string { return $this->last_name; } /** * Email. */ public function email(): ?string { return $this->email; } /** * Phone. */ public function phone(): ?string { return $this->phone; } /** * Marketing consent. */ public function marketing_consent(): bool { return $this->marketing_consent; } /** * Terms accepted. */ public function terms_accepted(): bool { return $this->terms_accepted; } /** * Custom fields. * * @return array */ public function custom_fields(): array { return $this->custom_fields; } /** * Notes. */ public function notes(): ?string { return $this->notes; } /** * Persistable array. * * @return array */ public function to_array(): array { return [ 'first_name' => $this->first_name, 'last_name' => $this->last_name, 'email' => $this->email, 'phone' => $this->phone, 'marketing_consent' => $this->marketing_consent, 'terms_accepted' => $this->terms_accepted, 'custom_fields' => $this->custom_fields, 'notes' => $this->notes, ]; } }