order_intent_id < 1 ) { throw new DomainException( 'cart.order_intent_id', 'order_intent_id must be positive.' ); } } /** * 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; } /** * Parent order intent id. * * @since 0.1.0 */ public function order_intent_id(): int { return $this->order_intent_id; } /** * Status. * * @since 0.1.0 */ public function status(): CartStatus { return $this->status; } /** * 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; } /** * Assign id after insert. * * @param int $id New id. * * @throws DomainException When already assigned. * * @since 0.1.0 */ public function assign_id( int $id ): void { if ( null !== $this->id ) { throw new DomainException( 'cart.id_assigned', 'Cart id is already assigned.' ); } if ( $id < 1 ) { throw new DomainException( 'cart.id_invalid', 'Cart id must be positive.' ); } $this->id = $id; } /** * Transition status. * * @param CartStatus $status New status. * @param DateTimeImmutable $now Instant. * * @since 0.1.0 */ public function set_status( CartStatus $status, DateTimeImmutable $now ): void { $this->status = $status; $this->updated_at = $now->setTimezone( new DateTimeZone( 'UTC' ) ); } }