ChatSession.php

Code Hygiene Score: 90

Keine Issues gefunden.

Dependencies 5

Klassen 1

Funktionen 21

Verwendet von 10

Versionen 18

Code

<?php

declare(strict_types=1);

namespace Domain\Entity;

// @responsibility: Repräsentiert eine Chat-Session mit ihren Metadaten

use Domain\ValueObject\SessionMetadata;
use Domain\ValueObject\SessionUuid;

class ChatSession
{
    public function __construct(
        private readonly SessionUuid $uuid,
        private readonly SessionMetadata $metadata,
        private readonly ?int $id = null,
        private readonly ?string $sessionToken = null,
        private readonly ?int $userId = null,
        private readonly ?int $personaId = null,
        private readonly ?string $title = null,
        private readonly ?int $authorProfileId = null,
        private readonly ?int $systemPromptId = null,
        private readonly \DateTimeImmutable $createdAt = new \DateTimeImmutable(),
        private readonly \DateTimeImmutable $updatedAt = new \DateTimeImmutable(),
        private readonly \DateTimeImmutable $lastActivity = new \DateTimeImmutable()
    ) {
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getUuid(): string
    {
        return $this->uuid->value();
    }

    public function getUuidObject(): SessionUuid
    {
        return $this->uuid;
    }

    public function getSessionToken(): ?string
    {
        return $this->sessionToken;
    }

    public function getUserId(): ?int
    {
        return $this->userId;
    }

    public function getPersonaId(): ?int
    {
        return $this->personaId;
    }

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function getModel(): string
    {
        return $this->metadata->getModel();
    }

    /** @return array<string> */
    public function getCollections(): array
    {
        return $this->metadata->getCollections();
    }

    public function getContextLimit(): int
    {
        return $this->metadata->getContextLimit();
    }

    public function getTemperature(): float
    {
        return $this->metadata->getTemperature();
    }

    public function getMaxTokens(): int
    {
        return $this->metadata->getMaxTokens();
    }

    public function getAuthorProfileId(): ?int
    {
        return $this->authorProfileId;
    }

    public function getSystemPromptId(): ?int
    {
        return $this->systemPromptId;
    }

    public function getCreatedAt(): \DateTimeImmutable
    {
        return $this->createdAt;
    }

    public function getUpdatedAt(): \DateTimeImmutable
    {
        return $this->updatedAt;
    }

    public function getLastActivity(): \DateTimeImmutable
    {
        return $this->lastActivity;
    }

    public function withId(int $id): self
    {
        return new self(
            $this->uuid,
            $this->metadata,
            $id,
            $this->sessionToken,
            $this->userId,
            $this->personaId,
            $this->title,
            $this->authorProfileId,
            $this->systemPromptId,
            $this->createdAt,
            $this->updatedAt,
            $this->lastActivity
        );
    }

    public function withTitle(string $title): self
    {
        return new self(
            $this->uuid,
            $this->metadata,
            $this->id,
            $this->sessionToken,
            $this->userId,
            $this->personaId,
            $title,
            $this->authorProfileId,
            $this->systemPromptId,
            $this->createdAt,
            new \DateTimeImmutable(),
            new \DateTimeImmutable()
        );
    }

    public function updateSettings(
        string $model,
        array $collections,
        int $contextLimit,
        ?int $authorProfileId,
        float $temperature,
        int $maxTokens
    ): self {
        $newMetadata = SessionMetadata::create($model, $collections, $contextLimit, $temperature, $maxTokens);

        return new self(
            $this->uuid,
            $newMetadata,
            $this->id,
            $this->sessionToken,
            $this->userId,
            $this->personaId,
            $this->title,
            $authorProfileId,
            $this->systemPromptId,
            $this->createdAt,
            new \DateTimeImmutable(),
            new \DateTimeImmutable()
        );
    }
}
← Übersicht Graph