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

namespace WPLens\AI;

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

final class CitationResult {

	/** @var bool */
	public $ok;
	/** @var bool */
	public $cited;
	/** @var int|null */
	public $position;
	/** @var string|null */
	public $cited_url;
	/** @var array<int, string> */
	public $all_cited_urls;
	/** @var string */
	public $raw_excerpt;
	/** @var string|null */
	public $error_code;
	/** @var string|null */
	public $error_message;

	public function __construct(
		bool $ok,
		bool $cited = false,
		?int $position = null,
		?string $cited_url = null,
		array $all_cited_urls = array(),
		string $raw_excerpt = '',
		?string $error_code = null,
		?string $error_message = null
	) {
		$this->ok             = $ok;
		$this->cited          = $cited;
		$this->position       = $position;
		$this->cited_url      = $cited_url;
		$this->all_cited_urls = $all_cited_urls;
		$this->raw_excerpt    = $raw_excerpt;
		$this->error_code     = $error_code;
		$this->error_message  = $error_message;
	}

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