*/ public const VALID_STATUSES = [ self::STATUS_DRAFT, self::STATUS_PUBLISHED, self::STATUS_ARCHIVED ]; public function __construct( public readonly int $policyId, public readonly int $versionNumber, public readonly ?string $body = null, public readonly string $status = self::STATUS_DRAFT, public readonly ?string $publishedAt = null, public readonly ?int $id = null, ) {} public static function fromRow( \stdClass $row ): self { return new self( policyId: Val::int( $row->policy_id ), versionNumber: Val::int( $row->version_number ), body: Val::stringOrNull( $row->body ), status: Val::string( $row->status ), publishedAt: Val::stringOrNull( $row->published_at ), id: Val::int( $row->id ), ); } public function isPublished(): bool { return self::STATUS_PUBLISHED === $this->status; } /** * Returns a plain array representation of the version. * * @return array */ public function toArray(): array { return [ 'id' => $this->id, 'policy_id' => $this->policyId, 'version_number' => $this->versionNumber, 'body' => $this->body, 'status' => $this->status, 'published_at' => $this->publishedAt, ]; } }