<?php

namespace AtlasAiDev\Awfah\Integrations;

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

// This class extends the official AI plugin's Abstract_Feature, so it must
// never be parsed while that plugin is inactive. Wpai_Bridge only references
// it behind an is_wpai_active() guard; this belt-and-suspenders check covers
// direct autoloads (e.g. a stale classmap scan).
if ( ! class_exists( '\WordPress\AI\Abstracts\Abstract_Feature' ) ) {
    return;
}

use WordPress\AI\Abstracts\Abstract_Feature;
use WordPress\AI\Experiments\Experiment_Category;

/**
 * Our excerpt-generation experiment, registered as a Feature in the official
 * AI plugin's framework (pilot for AI-10).
 *
 * This intentionally carries NO behavior of its own beyond enablement
 * signalling: the actual UI/enqueue stays in Editor_Experiments (our React
 * app, tones/templates/batch/history intact), and the generation backend
 * stays in Content_Steward_Abilities. Registering here gives users a toggle
 * card for it on the official Settings > AI screen next to the built-in
 * experiments, and groups us into the AI plugin's ecosystem (logging,
 * guidelines, future surfaces).
 */
class Wpai_Excerpt_Feature extends Abstract_Feature {

    public static function get_id(): string {
        return 'awfah-excerpt-generation';
    }

    /**
     * Metadata for the Settings > AI feature card.
     *
     * @return array{label:string, description:string, category:string}
     */
    protected function load_metadata(): array {
        return [
            'label'       => 'AtlasAI: ' . __( 'Excerpt Generation', 'ai-workflow-automation-ai-agent-hub' ),
            'description' => sprintf(
                /* translators: %s: plugin brand name (do not translate) */
                __( 'Advanced excerpt generation by %s — tone presets, prompt templates, batch variants, generation history, and per-request provider choice in the post sidebar.', 'ai-workflow-automation-ai-agent-hub' ),
                'AtlasAI Connector'
            ),
            'category'    => Experiment_Category::EDITOR,
        ];
    }

    /**
     * Called by the AI plugin only when this feature is enabled (global toggle
     * + the feature card toggle). Our editor enqueue checks this mark.
     */
    public function register(): void {
        Wpai_Bridge::mark_enabled( 'generate-excerpt' );
    }
}
