/**
 * ============================================================================
 * ARTICLE BUILDER - PROMPT CONFIGURATION
 * ============================================================================
 *
 * Central configuration for all workflow steps, their prompts, and input mappings.
 * This file defines the relationship between steps, prompt files, and user data.
 *
 * @author    @maurosicard
 * @version   2.0
 * ============================================================================
 */

const PROMPT_CONFIG = {
    /**
     * Workflow Steps Configuration
     * Maps each step to its prompt file and required inputs
     */
    steps: {
        0: {
            id: 'user-input',
            title: 'User Input',
            icon: 'bi-pencil-square',
            description: 'Begin your article workflow by providing the topic and any additional context.',
            hasPrompt: false, // This step collects input, doesn't display a prompt
            inputs: {
                articleTitle: {
                    type: 'text',
                    label: 'Article Title',
                    placeholder: 'e.g., How to integrate Stripe payments with Webflow',
                    required: true
                },
                articleContext: {
                    type: 'textarea',
                    label: 'Additional Context (Optional)',
                    placeholder: 'Provide any specific requirements, angles, or preferences for this article.',
                    required: false
                }
            }
        },

        1: {
            id: 'article-focus',
            title: 'Article Focus',
            icon: 'bi-compass',
            description: 'Determine the optimal direction for your article. This step validates that we\'re solving the right problem.',
            hasPrompt: true,
            promptFile: 'prompts/article-focus.md',
            dependencies: ['articleTitle', 'articleContext'],
            requiredSteps: [0],  // Requires user input
            placeholders: {
                '[INSERT_TOPIC]': 'articleTitle',
                '[INSERT_CONTEXT]': 'articleContext'
            }
        },

        2: {
            id: 'research-topic',
            title: 'Research Topic',
            icon: 'bi-search',
            description: 'Comprehensive fact-gathering phase. Collect technical requirements and best practices.',
            hasPrompt: true,
            promptFile: 'prompts/research-topic.md',
            dependencies: ['articleTitle', 'articleContext', 'articleFocus'],
            requiredSteps: [0, 1],  // Requires user input and article focus
            placeholders: {
                '[INSERT_TOPIC]': 'articleTitle',
                '[INSERT_CONTEXT]': 'articleContext',
                '[INSERT_ARTICLE_FOCUS]': 'articleFocus'
            }
        },

        3: {
            id: 'community-intelligence',
            title: 'Community Intel',
            icon: 'bi-people',
            description: 'Find real user questions, pain points, and discussions from community platforms.',
            hasPrompt: true,
            promptFile: 'prompts/community-intelligence.md',
            dependencies: ['articleTitle', 'articleContext', 'articleFocus'],
            requiredSteps: [0, 1],  // Requires user input and article focus
            placeholders: {
                '[INSERT_TOPIC]': 'articleTitle',
                '[INSERT_CONTEXT]': 'articleContext',
                '[INSERT_ARTICLE_FOCUS]': 'articleFocus'
            }
        },

        4: {
            id: 'find-seo-questions',
            title: 'SEO Questions',
            icon: 'bi-question-circle',
            description: 'Identify 40-50 specific search queries and FAQ opportunities.',
            hasPrompt: true,
            promptFile: 'prompts/find-seo-questions.md',
            dependencies: ['articleTitle', 'articleContext', 'articleFocus'],
            requiredSteps: [0, 1],  // Requires user input and article focus
            placeholders: {
                '[INSERT_TOPIC]': 'articleTitle',
                '[INSERT_CONTEXT]': 'articleContext',
                '[INSERT_ARTICLE_FOCUS]': 'articleFocus'
            }
        },

        5: {
            id: 'article-structure-planner',
            title: 'Article Structure',
            icon: 'bi-kanban',
            description: 'Generate a refined article structure with technical explanations and suggestions.',
            hasPrompt: true,
            promptFile: 'SIMPLIFICATION-EXAMPLES.md',
            dependencies: ['articleTitle', 'articleContext', 'articleFocus', 'researchTopic', 'communityIntel', 'seoQuestions'],
            requiredSteps: [0, 1, 2, 3, 4],
            placeholders: {
                '[INSERT_ARTICLE_TITLE]': 'articleTitle',
                '[INSERT_ARTICLE_CONTEXT]': 'articleContext',
                '[INSERT_ARTICLE_FOCUS_RESULT]': 'articleFocus',
                '[INSERT_RESEARCH_TOPIC_RESULT]': 'researchTopic',
                '[INSERT_COMMUNITY_INTEL_RESULT]': 'communityIntel',
                '[INSERT_SEO_QUESTIONS_RESULT]': 'seoQuestions'
            }
        },

        6: {
            id: 'generate-article',
            title: 'Generate Article',
            icon: 'bi-file-text',
            description: 'Create the comprehensive final article using all research.',
            hasPrompt: true,
            promptFile: 'prompts/generate-article.md',
            dependencies: ['articleTitle', 'articleContext'],
            requiredSteps: [0, 1, 2, 3, 4],  // Requires user input, article focus, research, community, and SEO steps (Step 5 is optional)
            placeholders: {
                '[INSERT_TOPIC]': 'articleTitle',
                '[INSERT_CONTEXT]': 'articleContext',
                '[INSERT_ARTICLE_FOCUS]': 'articleFocus',
                '[INSERT_RESEARCH_TOPIC]': 'researchTopic',
                '[INSERT_COMMUNITY_INTEL]': 'communityIntel',
                '[INSERT_SEO_QUESTIONS]': 'seoQuestions'
            }
        },

        7: {
            id: 'diagram-designer',
            title: 'Diagram Designer',
            icon: 'bi-diagram-3',
            description: 'Create static visual diagrams using the final article content.',
            hasPrompt: true,
            hasDualPrompts: true,
            promptFile: 'prompts/diagram-designer.md',
            promptFile2: 'prompts/diagram-designer-for-sora.md',
            dependencies: ['articleTitle'],
            requiredSteps: [0, 6],  // Requires user input and generated article
            placeholders: {
                '[INSERT_TOPIC]': 'articleTitle',
                '[INSERT_ARTICLE]': 'articleContent'
            }
        },

        8: {
            id: 'featured-image',
            title: 'Featured Image',
            icon: 'bi-image',
            description: 'Generate AI image prompts for blog featured images.',
            hasPrompt: true,
            promptFile: 'prompts/featured-image.md',
            dependencies: ['articleTitle'],
            requiredSteps: [0, 6],  // Requires user input and generated article
            placeholders: {
                '[INSERT_TOPIC]': 'articleTitle',
                '[INSERT_ARTICLE]': 'articleContent'
            }
        },

        9: {
            id: 'seo-meta-data',
            title: 'SEO Meta Data',
            icon: 'bi-card-heading',
            description: 'Generate optimized SEO metadata for the article.',
            hasPrompt: true,
            promptFile: 'prompts/seo-meta-data.md',
            dependencies: ['articleTitle'],
            requiredSteps: [0, 6],  // Requires user input and generated article
            placeholders: {
                '[INSERT_TOPIC]': 'articleTitle',
                '[INSERT_ARTICLE]': 'articleContent'
            }
        }
    },

    /**
     * Get step configuration by number
     * @param {number} stepNumber - The step number (0-9)
     * @returns {object} Step configuration object
     */
    getStep(stepNumber) {
        return this.steps[stepNumber] || null;
    },

    /**
     * Get all steps that have prompts
     * @returns {array} Array of step configurations with prompts
     */
    getPromptSteps() {
        return Object.entries(this.steps)
            .filter(([_, config]) => config.hasPrompt)
            .map(([number, config]) => ({ number: parseInt(number), ...config }));
    },

    /**
     * Get dependency names for a step (for UI display)
     * @param {number} stepNumber - The step number
     * @returns {string} Formatted dependency list with HTML
     */
    getDependencyText(stepNumber) {
        const step = this.getStep(stepNumber);
        if (!step || !step.dependencies) return '';

        const depMap = {
            'articleTitle': '<strong>Article Title</strong>',
            'articleContext': '<strong>Additional Context</strong>',
            'articleFocus': '<strong>Article Focus Results</strong>'
        };

        return step.dependencies
            .map(dep => depMap[dep] || dep)
            .join(' and ') + ' from previous steps.';
    }
};

// Export for use in other modules
if (typeof module !== 'undefined' && module.exports) {
    module.exports = PROMPT_CONFIG;
}
