<?php

declare(strict_types=1);

namespace ProRank\SEO\Core\Content;

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

/**
 * Catalogue of HTML attributes that leak from AI chat surfaces when content
 * is copy-pasted into a WordPress editor.
 *
 * "high_confidence" attributes are specific enough to strip automatically.
 * "ambiguous" attributes are also used by legitimate tooling, editors,
 * component libraries, or site-specific markup - detect and report, but do
 * not auto-strip.
 */
final class AiContentLeakSignatures {

    public const HIGH_CONFIDENCE = [
        // OpenAI / ChatGPT — streaming chunk markers + message envelope
        'data-start' => 'chatgpt',
        'data-end' => 'chatgpt',
        'data-message-id' => 'chatgpt',
        'data-message-author-role' => 'chatgpt',
        'data-message-model-slug' => 'chatgpt',

        // Anthropic / Claude artifact wrapper.
        'data-claude-artifact-id' => 'claude',

        // Perplexity AI.
        'data-perplexity-id' => 'perplexity',
    ];

    public const AMBIGUOUS = [
        // These can appear in AI UIs, but they are generic enough that removing
        // them automatically could break legitimate markup or editor state.
        'data-message-role' => 'claude',

        // Google / Gemini & Bard surfaces.
        'data-response-index' => 'gemini',
        'data-message-index' => 'gemini',
        'data-mat-id' => 'gemini',

        // Microsoft Copilot and embedded chat widgets.
        'data-content-id' => 'copilot',
        'data-bot-message-id' => 'copilot',

        // Draft.js / Slate.js editors used by some AI front-ends and by
        // legitimate editors.
        'data-block-key' => 'draftjs',
        'data-offset-key' => 'draftjs',

        // Used by AI UIs AND by Cypress/Playwright/React Testing Library/component kits.
        // Detect & report but do not auto-strip — could break legitimate theme/plugin code.
        'data-testid' => 'ambiguous_test_marker',
        'data-test-id' => 'ambiguous_test_marker',
        'data-cy' => 'ambiguous_test_marker',
        'data-qa' => 'ambiguous_test_marker',
    ];

    public static function all_attributes(): array {
        return array_merge(array_keys(self::HIGH_CONFIDENCE), array_keys(self::AMBIGUOUS));
    }

    public static function high_confidence_attributes(): array {
        return array_keys(self::HIGH_CONFIDENCE);
    }

    public static function vendor_for(string $attribute): string {
        return self::HIGH_CONFIDENCE[$attribute] ?? self::AMBIGUOUS[$attribute] ?? 'unknown';
    }
}
