<?php
/**
 * ==========================
 * 🔐 IGNY8 FILE RULE HEADER
 * ==========================
 * @file         : prompts-library.php
 * @location     : /ai/prompts-library.php
 * @type         : AI Integration
 * @scope        : Global
 * @allowed      : AI prompts, prompt management, AI templates
 * @reusability  : Globally Reusable
 * @notes        : Central AI prompts library for all modules
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Default clustering prompt template
 */
function igny8_get_default_clustering_prompt() {
    return "Analyze the following keywords and group them into topic clusters.

Each cluster should include:
- \"name\": A clear, descriptive topic name
- \"description\": A brief explanation of what the cluster covers
- \"keywords\": A list of related keywords that belong to this cluster

Format the output as a JSON object with a \"clusters\" array.

Clustering rules:
- Group keywords based on strong semantic or topical relationships (intent, use-case, function, audience, etc.)
- Clusters should reflect how people actually search — problem ➝ solution, general ➝ specific, product ➝ benefit, etc.
- Avoid grouping keywords just because they share similar words — focus on meaning
- Include 3–10 keywords per cluster where appropriate
- Skip unrelated or outlier keywords that don't fit a clear theme

Keywords to process:
[IGNY8_KEYWORDS]";
}

/**
 * Default ideas prompt template
 */
function igny8_get_default_ideas_prompt() {
    return "Generate SEO-optimized, high-quality content ideas and detailed outlines for each of the following keyword clusters. Each idea must be valuable for SEO, have clear editorial flow, and include a structured long-form content outline that matches the standards of our content generation system.

==========================
CONTENT IDEA INPUT FORMAT
==========================

Clusters to analyze:
[IGNY8_CLUSTERS]

Keywords in each cluster:
[IGNY8_CLUSTER_KEYWORDS]

======================
OUTPUT FORMAT REQUIRED
======================

Return your response as JSON with an \"ideas\" array.
For each cluster, you must generate exactly 1 cluster_hub page and 2–4 supporting blog/article ideas based on unique keyword dimensions.

Each idea must include:

- \"title\": compelling blog/article title that naturally includes a primary keyword
- \"description\": detailed and structured content outline using proper H2/H3 breakdowns (see outline rules below)
- \"content_type\": the type of content (post, page)
- \"content_structure\": the editorial structure (cluster_hub, guide_tutorial, how_to, comparison, review, top_listicle, question)
- \"cluster_id\": ID of the cluster this idea belongs to
- \"estimated_word_count\": estimated total word count (range: 1500–2200 words)
- \"covered_keywords\": comma-separated list of keywords from the cluster that will be covered naturally in the content

=========================
OUTLINE (DESCRIPTION) RULES
=========================

Each content idea's \"description\" must follow the expected editorial structure based on both the content_type and content_structure fields. It should be formatted as a professional long-form content outline, suitable for direct use by AI or human writers.

1. STRUCTURE:
   - INTRODUCTION SECTION: Start with 1 hook (italic, 30-40 words) followed by 2 intro paragraphs (50-60 words each)
   - Use exactly 5–8 H2 sections (depending on content type)
   - Each H2 section should contain 2–3 H3 subsections
   - SECTION WORD COUNT: Each H2 section should be 250-300 words total
   - CONTENT MIX: Vary content types within sections:
     - Some sections: 1 paragraph + list/table + 1 paragraph
     - Some sections: 2 paragraphs + list/table (as final element)
     - Mix unordered lists, ordered lists, and tables strategically
   - Use diverse formatting styles: data/stat mentions, expert quotes, comparative breakdowns

2. FORMATTING TYPES:
   - content_type: \"paragraph\", \"list\", \"table\", \"blockquote\", or \"mixed\"
   - Do not open sections or subheadings with bullet points or generic phrasing
   - Use bullet lists or tables only after sufficient paragraph setup
   - Tables should have defined columns (e.g., Feature, Benefit, Product Name, Price, Link)
   - Blockquotes should contain expert insight, best practices, or unique POV
   - Ensure each section varies in tone and structure from others

3. QUALITY & DEPTH:
   - Write for depth and uniqueness, not surface-level filler
   - Use primary keyword in title, intro, and at least 2 H2 sections
   - Use secondary keywords naturally throughout outline
   - Suggest informative, useful angles that solve a real problem or offer unique value
   - Avoid repeated structure across all ideas — each outline should feel hand-edited

==========================
TONE & FLOW REQUIREMENTS
==========================

- Maintain a professional, editorial tone — not robotic or templated
- No generic intros like \"In today's article…\"
- Begin sections with direct, engaging sentences — not summaries of the heading
- Use real-world examples, relevant context, or recent data wherever useful
- Include ideas that could incorporate user intent like tutorials, comparisons, or decision support

==========================
FINAL RETURN FORMAT (JSON)
==========================
{
  \"ideas\": [
    {
      \"title\": \"Best Organic Cotton Duvet Covers for All Seasons\",
      \"description\": {
        \"introduction\": {
          \"hook\": \"Transform your sleep with organic cotton that blends comfort and sustainability.\",
          \"paragraphs\": [
            {
              \"content_type\": \"paragraph\",
              \"details\": \"Overview of organic cotton's rise in bedding industry.\"
            },
            {
              \"content_type\": \"paragraph\",
              \"details\": \"Why consumers prefer organic bedding over synthetic alternatives.\"
            }
          ]
        },
        \"H2\": [
          {
            \"heading\": \"Why Choose Organic Cotton for Bedding?\",
            \"subsections\": [
              {
                \"subheading\": \"Health and Skin Benefits\",
                \"content_type\": \"paragraph\",
                \"details\": \"Discuss hypoallergenic and chemical-free aspects.\"
              },
              {
                \"subheading\": \"Environmental Sustainability\",
                \"content_type\": \"list\",
                \"details\": \"Bullet list of eco benefits like low water use, no pesticides.\"
              },
              {
                \"subheading\": \"Long-Term Cost Savings\",
                \"content_type\": \"table\",
                \"details\": \"Table comparing durability and pricing over time.\"
              }
            ]
          },
          {
            \"heading\": \"Top Organic Cotton Duvet Brands\",
            \"subsections\": [
              {
                \"subheading\": \"Brand 1 Overview\",
                \"content_type\": \"paragraph\",
                \"details\": \"Description of features, pricing, and audience fit.\"
              },
              {
                \"subheading\": \"Brand 2 Overview\",
                \"content_type\": \"paragraph\",
                \"details\": \"Highlight what makes this brand stand out.\"
              },
              {
                \"subheading\": \"Quick Comparison Table\",
                \"content_type\": \"table\",
                \"details\": \"Side-by-side feature and price comparison.\"
              }
            ]
          }
        ]
      },
      \"content_type\": \"post\",
      \"content_structure\": \"review\",
      \"cluster_id\": 12,
      \"estimated_word_count\": 1800,
      \"covered_keywords\": \"organic duvet covers, eco-friendly bedding, sustainable sheets\"
    }
  ]
}

==============================
NOTES FOR EXECUTION ENGINE
==============================

- Make sure all outlines follow this structure and are unique in flow and format.
- Do not reuse same outline patterns across ideas.
- Emphasize depth, paragraph-first formatting, and mixed content presentation.
- Ensure final output is usable by long-form AI content systems and human writers alike.";
}

/**
 * Default content generation prompt template
 */
function igny8_content_generation_prompt() {
    return "You are an editorial content strategist. Your task is to generate a complete JSON response object that includes all the fields listed below, based on the provided content idea, keyword cluster, and keyword list.

Only the `content` field should contain HTML. All other fields must be plain JSON values.

==================
CONTENT OBJECT STRUCTURE
==================

{
  \"title\": \"[Auto-generate a compelling blog title using the primary keyword]\",
  \"meta_title\": \"[SEO-optimized meta title under 60 characters]\",
  \"meta_description\": \"[SEO-friendly summary under 160 characters]\",
  \"content\": \"[HTML body — see structure rules below]\",
  \"word_count\": [Exact word count of the HTML content],
  \"primary_keyword\": \"[Provided primary keyword]\",
  \"secondary_keywords\": [List of provided secondary keywords],
  \"keywords_used\": [List of all keywords actually used in the HTML content],
  \"tags\": [List of 5 lowercase tags (2–4 words each)],
  \"categories\": [\"Parent > Child\", \"Optional 2nd category if needed\"],
  [IMAGE_PROMPTS]
}

===========================
CONTENT FORMAT & STRUCTURE
===========================

- Use only valid WP-supported HTML blocks: <h2>, <h3>, <p>, <ul>/<ol>, and <table>
- Do not add extra line breaks, empty tags, or inconsistent spacing
- Use proper table structure when using tables:
<table>
<thead>
    <tr><th>col heading1</th><th>col heading2</th></tr>
</thead>
<tbody>
    <tr>
        <td>cell1</td><td>cell2</td>
    </tr>
</tbody>
</table>

===========================
CONTENT FLOW RULES
===========================

**INTRODUCTION:**
- Start with 1 italicized hook (30–40 words)
- Follow with 2 narrative paragraphs (each 50–60 words; 2–3 sentences max)
- No headings allowed in intro

**H2 SECTIONS (5–8 total):**
Each section should be 250–300 words and follow this format:
1. Two narrative paragraphs (80–120 words each, 2–3 sentences)
2. One list or table (must come *after* a paragraph)
3. Optional closing paragraph (40–60 words)
4. Insert 2–3 <h3> subsections naturally after main paragraphs

**Formatting Rules:**
- Vary use of unordered lists, ordered lists, and tables across sections
- Never begin any section or sub-section with a list or table

===========================
KEYWORD & SEO RULES
===========================

- **Primary keyword** must appear in:
  - The title
  - First paragraph of the introduction
  - At least 2 H2 headings

- **Secondary keywords** must be used naturally, not forced

- **Tone & style guidelines:**
  - No robotic or passive voice
  - Avoid generic intros like \"In today's world…\"
  - Don't repeat heading in opening sentence
  - Vary sentence structure and length

===========================
IMAGE PROMPT RULES
===========================

- Provide detailed, specific, and relevant image prompts
- Each prompt should reflect the topic/subtopic in that section
- Avoid vague or generic prompts

===========================
INPUT VARIABLES
===========================

CONTENT IDEA DETAILS:
[IGNY8_IDEA]

KEYWORD CLUSTER:
[IGNY8_CLUSTER]

ASSOCIATED KEYWORDS:
[IGNY8_KEYWORDS]

===========================
OUTPUT FORMAT
===========================

Return ONLY the final JSON object.  
Do NOT include any comments, formatting, or explanations.";
}
