<?php

/**
 * DeepSeek model ID normalization (V4-only catalog).
 *
 * @package LolaCore\LLM\Providers\DeepSeek
 * @license GPL-2.0-or-later
 */

declare(strict_types=1);

namespace LolaCore\LLM\Providers\DeepSeek;

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

/**
 * Maps retired DeepSeek model slugs to current V4 equivalents.
 *
 * DeepSeek's public catalog is now deepseek-v4-flash and deepseek-v4-pro only.
 * Sites may still have deepseek-chat / deepseek-reasoner stored in lolacore_config.
 */
final class DeepSeekModelSupport {

	public const MODEL_FLASH = 'deepseek-v4-flash';

	public const MODEL_PRO = 'deepseek-v4-pro';

	/** @var array<string, string> Retired model ID => current replacement. */
	private const LEGACY_ALIASES = array(
		'deepseek-chat'     => self::MODEL_FLASH,
		'deepseek-reasoner' => self::MODEL_PRO,
	);

	/**
	 * Replace legacy stored model IDs with a supported V4 slug.
	 */
	public static function normalizeId( string $modelId ): string {
		$modelId = trim($modelId);
		if ($modelId === '') {
			return self::MODEL_FLASH;
		}

		return self::LEGACY_ALIASES[ $modelId ] ?? $modelId;
	}

	/**
	 * Whether the model belongs to the current DeepSeek V4 catalog.
	 */
	public static function isV4Model( string $modelId ): bool {
		return str_starts_with(self::normalizeId($modelId), 'deepseek-v4-');
	}

	/**
	 * Plugin Builder and codegen should disable thinking mode on V4 models.
	 */
	public static function shouldDisableThinkingForCodegen( string $modelId ): bool {
		return self::isV4Model($modelId);
	}
}
