service_id < 1 ) { throw new DomainException( 'duration.service_id', 'service_id must be positive.' ); } if ( $this->duration_min < 1 ) { throw new DomainException( 'duration.minutes', 'duration_min must be at least 1.' ); } if ( $this->price->is_negative() ) { throw new DomainException( 'duration.price_negative', 'Duration price must not be negative.' ); } } /** * Database id. * * @since 0.1.0 */ public function id(): ?int { return $this->id; } /** * Service id. * * @since 0.1.0 */ public function service_id(): int { return $this->service_id; } /** * Duration min. * * @since 0.1.0 */ public function duration_min(): int { return $this->duration_min; } /** * Price. * * @since 0.1.0 */ public function price(): Money { return $this->price; } /** * Label. * * @since 0.1.0 */ public function label(): ?string { return $this->label; } /** * Is default. * * @since 0.1.0 */ public function is_default(): bool { return $this->is_default; } /** * Sort order. * * @since 0.1.0 */ public function sort_order(): int { return $this->sort_order; } /** * 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( 'duration.id_assigned', 'Duration id is already assigned.' ); } $this->id = $id; } }