|null $meta Meta. * @param DateTimeImmutable $created_at Created UTC. * @param DateTimeImmutable $updated_at Updated UTC. * @param DateTimeImmutable|null $deleted_at Soft delete. * * @throws \Bookline\Domain\Shared\DomainException When invariants fail. */ public function __construct( private ?int $id, private Uuid $uuid, private string $name, private string $slug, private ?string $address_line1, private ?string $address_line2, private ?string $city, private ?string $region, private ?string $postcode, private ?string $country, private ?string $latitude, private ?string $longitude, private TimeZoneId $timezone, private ?PhoneNumber $phone, private ?EmailAddress $email, private LocationStatus $status, private ?string $colour, private ?array $meta, private DateTimeImmutable $created_at, private DateTimeImmutable $updated_at, private ?DateTimeImmutable $deleted_at = null, ) { if ( '' === trim( $this->name ) ) { throw new DomainException( 'location.name_empty', 'Location name must not be empty.' ); } if ( '' === trim( $this->slug ) ) { throw new DomainException( 'location.slug_empty', 'Location slug must not be empty.' ); } if ( null !== $this->country && 1 !== preg_match( '/^[A-Z]{2}$/', $this->country ) ) { throw new DomainException( 'location.country', 'Country must be a 2-letter ISO code.' ); } if ( null !== $this->colour && 1 !== preg_match( '/^#[0-9A-Fa-f]{6}$/', $this->colour ) ) { throw new DomainException( 'location.colour_invalid', 'Colour must be #RRGGBB.' ); } } /** * Database id. * * @since 0.1.0 */ public function id(): ?int { return $this->id; } /** * Public UUID. * * @since 0.1.0 */ public function uuid(): Uuid { return $this->uuid; } /** * Name. * * @since 0.1.0 */ public function name(): string { return $this->name; } /** * Slug. * * @since 0.1.0 */ public function slug(): string { return $this->slug; } /** * Address line1. * * @since 0.1.0 */ public function address_line1(): ?string { return $this->address_line1; } /** * Address line2. * * @since 0.1.0 */ public function address_line2(): ?string { return $this->address_line2; } /** * City. * * @since 0.1.0 */ public function city(): ?string { return $this->city; } /** * Region. * * @since 0.1.0 */ public function region(): ?string { return $this->region; } /** * Postcode. * * @since 0.1.0 */ public function postcode(): ?string { return $this->postcode; } /** * Country. * * @since 0.1.0 */ public function country(): ?string { return $this->country; } /** * Latitude. * * @since 0.1.0 */ public function latitude(): ?string { return $this->latitude; } /** * Longitude. * * @since 0.1.0 */ public function longitude(): ?string { return $this->longitude; } /** * Timezone. * * @since 0.1.0 */ public function timezone(): TimeZoneId { return $this->timezone; } /** * Phone. * * @since 0.1.0 */ public function phone(): ?PhoneNumber { return $this->phone; } /** * Email. * * @since 0.1.0 */ public function email(): ?EmailAddress { return $this->email; } /** * Status. * * @since 0.1.0 */ public function status(): LocationStatus { return $this->status; } /** * Colour. * * @since 0.1.0 */ public function colour(): ?string { return $this->colour; } /** * Opaque meta payload. * * @return array|null * * @since 0.1.0 */ public function meta(): ?array { return $this->meta; } /** * 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; } /** * Deleted at. * * @since 0.1.0 */ public function deleted_at(): ?DateTimeImmutable { return $this->deleted_at; } /** * Whether soft-deleted. * * @since 0.1.0 */ public function is_deleted(): bool { return null !== $this->deleted_at; } /** * Assign the database id after insert. * * @param int $id New id. * * @throws \Bookline\Domain\Shared\DomainException When id is already set or invalid. * * @since 0.1.0 */ public function assign_id( int $id ): void { if ( null !== $this->id ) { throw new DomainException( 'location.id_assigned', 'Location id is already assigned.' ); } $this->id = $id; } /** * Constructor. * * @param DateTimeImmutable $when Deletion instant UTC. * * @since 0.1.0 */ public function soft_delete( DateTimeImmutable $when ): void { if ( null !== $this->deleted_at ) { return; } $this->deleted_at = $when; $this->updated_at = $when; $this->status = LocationStatus::Inactive; } }