src/Entity/CRM/CallEvaluation.php line 13

  1. <?php
  2. namespace App\Entity\CRM;
  3. use App\Enum\CallEvaluationStatus;
  4. use App\Enum\SentimentLabel;
  5. use App\Repository\CRM\CallEvaluationRepository;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassCallEvaluationRepository::class)]
  9. #[ORM\Table(name'call_evaluation')]
  10. class CallEvaluation
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\OneToOne(inversedBy'evaluation'targetEntityTranscriptionJob::class)]
  17.     #[ORM\JoinColumn(name'transcription_job_id'nullablefalseuniquetrueonDelete'CASCADE')]
  18.     private ?TranscriptionJob $transcriptionJob null;
  19.     #[ORM\ManyToOne]
  20.     #[ORM\JoinColumn(name'tenant_id'nullabletrueonDelete'SET NULL')]
  21.     private ?Branch $tenant null;
  22.     #[ORM\Column(length24enumTypeCallEvaluationStatus::class)]
  23.     private CallEvaluationStatus $status CallEvaluationStatus::PENDING;
  24.     // --- SPRZEDAŻ ---
  25.     #[ORM\Column(typeTypes::SMALLINTnullabletrue)]
  26.     private ?int $salesScore null;
  27.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  28.     private ?string $salesAssessment null;
  29.     /**
  30.      * @var array<int, string>|null
  31.      */
  32.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  33.     private ?array $keyPoints null;
  34.     /**
  35.      * @var array<int, string>|null
  36.      */
  37.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  38.     private ?array $redFlags null;
  39.     // --- SENTYMENT ---
  40.     #[ORM\Column(length16nullabletrueenumTypeSentimentLabel::class)]
  41.     private ?SentimentLabel $sentimentLabel null;
  42.     #[ORM\Column(typeTypes::SMALLINTnullabletrue)]
  43.     private ?int $sentimentScore null;
  44.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  45.     private ?string $sentimentRationale null;
  46.     // --- OCENA CAŁOŚCIOWA ---
  47.     #[ORM\Column(typeTypes::SMALLINTnullabletrue)]
  48.     private ?int $overallScore null;
  49.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  50.     private ?string $overallSummary null;
  51.     // --- METADANE WYWOŁANIA ---
  52.     #[ORM\Column(length64nullabletrue)]
  53.     private ?string $model null;
  54.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  55.     private ?string $rawResponse null;
  56.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  57.     private ?string $error null;
  58.     #[ORM\Column(typeTypes::SMALLINT)]
  59.     private int $attempts 0;
  60.     #[ORM\Column(typeTypes::INTEGERnullabletrue)]
  61.     private ?int $durationMs null;
  62.     #[ORM\Column(typeTypes::SMALLINT)]
  63.     private int $chunkCount 1;
  64.     // --- ŚLAD WERSJI PROMPTÓW (audit) ---
  65.     #[ORM\ManyToOne(targetEntityPromptTemplateVersion::class)]
  66.     #[ORM\JoinColumn(name'prompt_system_version_id'nullabletrueonDelete'SET NULL')]
  67.     private ?PromptTemplateVersion $promptSystemVersion null;
  68.     #[ORM\ManyToOne(targetEntityPromptTemplateVersion::class)]
  69.     #[ORM\JoinColumn(name'prompt_sales_version_id'nullabletrueonDelete'SET NULL')]
  70.     private ?PromptTemplateVersion $promptSalesVersion null;
  71.     #[ORM\ManyToOne(targetEntityPromptTemplateVersion::class)]
  72.     #[ORM\JoinColumn(name'prompt_sentiment_version_id'nullabletrueonDelete'SET NULL')]
  73.     private ?PromptTemplateVersion $promptSentimentVersion null;
  74.     #[ORM\ManyToOne(targetEntityPromptTemplateVersion::class)]
  75.     #[ORM\JoinColumn(name'prompt_overall_version_id'nullabletrueonDelete'SET NULL')]
  76.     private ?PromptTemplateVersion $promptOverallVersion null;
  77.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  78.     private \DateTimeInterface $createdAt;
  79.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  80.     private ?\DateTimeInterface $evaluatedAt null;
  81.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  82.     private ?\DateTimeInterface $lockedAt null;
  83.     #[ORM\Column(length64nullabletrue)]
  84.     private ?string $lockedBy null;
  85.     public function __construct()
  86.     {
  87.         $this->createdAt = new \DateTimeImmutable();
  88.     }
  89.     public function __toString(): string
  90.     {
  91.         $jobLabel $this->transcriptionJob !== null ? (string) $this->transcriptionJob '?';
  92.         return sprintf('Ocena AI: %s'$jobLabel);
  93.     }
  94.     public function getId(): ?int
  95.     {
  96.         return $this->id;
  97.     }
  98.     public function getTranscriptionJob(): ?TranscriptionJob
  99.     {
  100.         return $this->transcriptionJob;
  101.     }
  102.     public function setTranscriptionJob(?TranscriptionJob $transcriptionJob): static
  103.     {
  104.         $this->transcriptionJob $transcriptionJob;
  105.         return $this;
  106.     }
  107.     public function getTenant(): ?Branch
  108.     {
  109.         return $this->tenant;
  110.     }
  111.     public function setTenant(?Branch $tenant): static
  112.     {
  113.         $this->tenant $tenant;
  114.         return $this;
  115.     }
  116.     public function getStatus(): CallEvaluationStatus
  117.     {
  118.         return $this->status;
  119.     }
  120.     public function setStatus(CallEvaluationStatus $status): static
  121.     {
  122.         $this->status $status;
  123.         return $this;
  124.     }
  125.     public function getSalesScore(): ?int
  126.     {
  127.         return $this->salesScore;
  128.     }
  129.     public function setSalesScore(?int $salesScore): static
  130.     {
  131.         $this->salesScore $salesScore !== null $this->clampScore($salesScore0100) : null;
  132.         return $this;
  133.     }
  134.     public function getSalesAssessment(): ?string
  135.     {
  136.         return $this->salesAssessment;
  137.     }
  138.     public function setSalesAssessment(?string $salesAssessment): static
  139.     {
  140.         $this->salesAssessment $salesAssessment;
  141.         return $this;
  142.     }
  143.     /**
  144.      * @return array<int, string>|null
  145.      */
  146.     public function getKeyPoints(): ?array
  147.     {
  148.         return $this->keyPoints;
  149.     }
  150.     /**
  151.      * @param array<int, string>|null $keyPoints
  152.      */
  153.     public function setKeyPoints(?array $keyPoints): static
  154.     {
  155.         $this->keyPoints $keyPoints;
  156.         return $this;
  157.     }
  158.     /**
  159.      * @return array<int, string>|null
  160.      */
  161.     public function getRedFlags(): ?array
  162.     {
  163.         return $this->redFlags;
  164.     }
  165.     /**
  166.      * @param array<int, string>|null $redFlags
  167.      */
  168.     public function setRedFlags(?array $redFlags): static
  169.     {
  170.         $this->redFlags $redFlags;
  171.         return $this;
  172.     }
  173.     public function getSentimentLabel(): ?SentimentLabel
  174.     {
  175.         return $this->sentimentLabel;
  176.     }
  177.     public function setSentimentLabel(?SentimentLabel $sentimentLabel): static
  178.     {
  179.         $this->sentimentLabel $sentimentLabel;
  180.         return $this;
  181.     }
  182.     public function getSentimentScore(): ?int
  183.     {
  184.         return $this->sentimentScore;
  185.     }
  186.     public function setSentimentScore(?int $sentimentScore): static
  187.     {
  188.         $this->sentimentScore $sentimentScore !== null $this->clampScore($sentimentScore, -100100) : null;
  189.         return $this;
  190.     }
  191.     public function getSentimentRationale(): ?string
  192.     {
  193.         return $this->sentimentRationale;
  194.     }
  195.     public function setSentimentRationale(?string $sentimentRationale): static
  196.     {
  197.         $this->sentimentRationale $sentimentRationale;
  198.         return $this;
  199.     }
  200.     public function getOverallScore(): ?int
  201.     {
  202.         return $this->overallScore;
  203.     }
  204.     public function setOverallScore(?int $overallScore): static
  205.     {
  206.         $this->overallScore $overallScore !== null $this->clampScore($overallScore0100) : null;
  207.         return $this;
  208.     }
  209.     public function getOverallSummary(): ?string
  210.     {
  211.         return $this->overallSummary;
  212.     }
  213.     public function setOverallSummary(?string $overallSummary): static
  214.     {
  215.         $this->overallSummary $overallSummary;
  216.         return $this;
  217.     }
  218.     public function getModel(): ?string
  219.     {
  220.         return $this->model;
  221.     }
  222.     public function setModel(?string $model): static
  223.     {
  224.         $this->model $model;
  225.         return $this;
  226.     }
  227.     public function getRawResponse(): ?string
  228.     {
  229.         return $this->rawResponse;
  230.     }
  231.     public function setRawResponse(?string $rawResponse): static
  232.     {
  233.         $this->rawResponse $rawResponse;
  234.         return $this;
  235.     }
  236.     public function getError(): ?string
  237.     {
  238.         return $this->error;
  239.     }
  240.     public function setError(?string $error): static
  241.     {
  242.         $this->error $error;
  243.         return $this;
  244.     }
  245.     public function getAttempts(): int
  246.     {
  247.         return $this->attempts;
  248.     }
  249.     public function setAttempts(int $attempts): static
  250.     {
  251.         $this->attempts max(0$attempts);
  252.         return $this;
  253.     }
  254.     public function incrementAttempts(int $delta 1): static
  255.     {
  256.         $this->attempts max(0$this->attempts $delta);
  257.         return $this;
  258.     }
  259.     public function getDurationMs(): ?int
  260.     {
  261.         return $this->durationMs;
  262.     }
  263.     public function setDurationMs(?int $durationMs): static
  264.     {
  265.         $this->durationMs $durationMs;
  266.         return $this;
  267.     }
  268.     public function getChunkCount(): int
  269.     {
  270.         return $this->chunkCount;
  271.     }
  272.     public function setChunkCount(int $chunkCount): static
  273.     {
  274.         $this->chunkCount max(1$chunkCount);
  275.         return $this;
  276.     }
  277.     public function getPromptSystemVersion(): ?PromptTemplateVersion
  278.     {
  279.         return $this->promptSystemVersion;
  280.     }
  281.     public function setPromptSystemVersion(?PromptTemplateVersion $promptSystemVersion): static
  282.     {
  283.         $this->promptSystemVersion $promptSystemVersion;
  284.         return $this;
  285.     }
  286.     public function getPromptSalesVersion(): ?PromptTemplateVersion
  287.     {
  288.         return $this->promptSalesVersion;
  289.     }
  290.     public function setPromptSalesVersion(?PromptTemplateVersion $promptSalesVersion): static
  291.     {
  292.         $this->promptSalesVersion $promptSalesVersion;
  293.         return $this;
  294.     }
  295.     public function getPromptSentimentVersion(): ?PromptTemplateVersion
  296.     {
  297.         return $this->promptSentimentVersion;
  298.     }
  299.     public function setPromptSentimentVersion(?PromptTemplateVersion $promptSentimentVersion): static
  300.     {
  301.         $this->promptSentimentVersion $promptSentimentVersion;
  302.         return $this;
  303.     }
  304.     public function getPromptOverallVersion(): ?PromptTemplateVersion
  305.     {
  306.         return $this->promptOverallVersion;
  307.     }
  308.     public function setPromptOverallVersion(?PromptTemplateVersion $promptOverallVersion): static
  309.     {
  310.         $this->promptOverallVersion $promptOverallVersion;
  311.         return $this;
  312.     }
  313.     public function getCreatedAt(): \DateTimeInterface
  314.     {
  315.         return $this->createdAt;
  316.     }
  317.     public function setCreatedAt(\DateTimeInterface $createdAt): static
  318.     {
  319.         $this->createdAt $createdAt;
  320.         return $this;
  321.     }
  322.     public function getEvaluatedAt(): ?\DateTimeInterface
  323.     {
  324.         return $this->evaluatedAt;
  325.     }
  326.     public function setEvaluatedAt(?\DateTimeInterface $evaluatedAt): static
  327.     {
  328.         $this->evaluatedAt $evaluatedAt;
  329.         return $this;
  330.     }
  331.     public function getLockedAt(): ?\DateTimeInterface
  332.     {
  333.         return $this->lockedAt;
  334.     }
  335.     public function setLockedAt(?\DateTimeInterface $lockedAt): static
  336.     {
  337.         $this->lockedAt $lockedAt;
  338.         return $this;
  339.     }
  340.     public function getLockedBy(): ?string
  341.     {
  342.         return $this->lockedBy;
  343.     }
  344.     public function setLockedBy(?string $lockedBy): static
  345.     {
  346.         $this->lockedBy $lockedBy;
  347.         return $this;
  348.     }
  349.     private function clampScore(int $valueint $minint $max): int
  350.     {
  351.         return max($minmin($max$value));
  352.     }
  353. }