success = $success; $this->content = $content; $this->errorMessage = $errorMessage; $this->tokensInput = $tokensInput; $this->tokensOutput = $tokensOutput; $this->durationMs = $durationMs; $this->model = $model; $this->metadata = $metadata; } public static function success( string $content, ?int $tokensInput = null, ?int $tokensOutput = null, ?int $durationMs = null, string $model = '', array $metadata = [] ): self { return new self( true, $content, null, $tokensInput, $tokensOutput, $durationMs, $model, $metadata ); } public static function error(string $errorMessage, string $model = '', array $metadata = []): self { return new self( false, null, $errorMessage, null, null, null, $model, $metadata ); } public function isSuccess(): bool { return $this->success; } public function getContent(): ?string { return $this->content; } public function getErrorMessage(): ?string { return $this->errorMessage; } public function getTokensInput(): ?int { return $this->tokensInput; } public function getTokensOutput(): ?int { return $this->tokensOutput; } public function getTokensTotal(): ?int { if ($this->tokensInput !== null && $this->tokensOutput !== null) { return $this->tokensInput + $this->tokensOutput; } return null; } public function getDurationMs(): ?int { return $this->durationMs; } public function getModel(): string { return $this->model; } public function getMetadata(): array { return $this->metadata; } public function toArray(): array { return [ 'success' => $this->success, 'content' => $this->content, 'error_message' => $this->errorMessage, 'tokens_input' => $this->tokensInput, 'tokens_output' => $this->tokensOutput, 'tokens_total' => $this->getTokensTotal(), 'duration_ms' => $this->durationMs, 'model' => $this->model, 'metadata' => $this->metadata, ]; } }