<?php
/**
 * OpenRouter Chat Model.
 *
 * Extends OpenAI Chat Model for OpenRouter-specific customizations.
 *
 * @package   Agenistrator
 * @since     1.0.0
 * @author    Alex Ruban <alex@maximum.guru>
 * @author    Maximum Software Inc <contact@maximum.software>
 * @license   GPL-3.0-only
 * @link      https://maximum.software/
 *
 * SPDX-FileCopyrightText: 2025-2026 Alex Ruban <alex@maximum.guru>
 * SPDX-FileCopyrightText: 2025-2026 Maximum Software Inc <contact@maximum.software>
 * SPDX-License-Identifier: GPL-3.0-only
 */

namespace Agenistrator;

// Direct access prevention
if ( ! defined( 'ABSPATH' ) ) {
	return;
}

/**
 * LLM_Chat_OpenRouter class.
 */
class LLM_Chat_OpenRouter extends LLM_Chat_OpenAI {
	/**
	 * Create a new context object specific to OpenRouter
	 *
	 * @param      string $system_message Optional custom system message
	 * @return     Context_OpenRouter OpenRouter-specific context object
	 * @since     1.0.0
	 */
	public function create_context( $system_message = null ) {
		return new Context_OpenRouter( $system_message );
	}

	/**
	 * Validate that the context is the correct type for this provider
	 *
	 * @param      Context $context Context object to validate
	 * @throws     \Exception If context is not the correct type
	 * @since     1.0.0
	 */
	protected function validate_context( $context ) {
		if ( ! ( $context instanceof Context_OpenRouter ) ) {
			// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Exception messages are not HTML output
			throw new \Exception(
				String_Utils::replace_tags(
					__( 'Invalid context type: expected {expected}, got {actual}', 'agenistrator' ),
					array(
						'expected' => 'Context_OpenRouter',
						'actual'   => get_class( $context ),
					)
				)
			);
			// phpcs:enable WordPress.Security.EscapeOutput.ExceptionNotEscaped
		}
	}
}
