<?php
/**
 * Result of a Provider::generate() call.
 *
 * @package WPLens
 */

namespace WPLens\AI;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

final class GenerationResult {

	/** @var bool */
	public $ok;
	/** @var string */
	public $text;
	/** @var int|null */
	public $input_tokens;
	/** @var int|null */
	public $output_tokens;
	/** @var string|null */
	public $error_code;
	/** @var string|null */
	public $error_message;

	public function __construct(
		bool $ok,
		string $text = '',
		?int $input_tokens = null,
		?int $output_tokens = null,
		?string $error_code = null,
		?string $error_message = null
	) {
		$this->ok            = $ok;
		$this->text          = $text;
		$this->input_tokens  = $input_tokens;
		$this->output_tokens = $output_tokens;
		$this->error_code    = $error_code;
		$this->error_message = $error_message;
	}

	public static function error( string $code, string $message ): self {
		return new self( false, '', null, null, $code, $message );
	}
}
