/**
 * PipelineTemplates.js
 *
 * Templates prédéfinis pour pipelines modulaires.
 * Fournit des configurations ready-to-use pour différents cas d'usage.
 */

/**
 * Templates de pipelines
 */
const TEMPLATES = {
  /**
   * Light & Fast - Pipeline minimal pour génération rapide
   */
  'light-fast': {
    name: 'Light & Fast',
    description: 'Pipeline rapide pour contenu basique, idéal pour tests et prototypes',
    pipeline: [
      { step: 1, module: 'generation', mode: 'simple', intensity: 1.0 },
      { step: 2, module: 'selective', mode: 'lightEnhancement', intensity: 0.7 }
    ],
    metadata: {
      author: 'system',
      created: '2025-10-08',
      version: '1.0',
      tags: ['fast', 'light', 'basic'],
      estimatedDuration: '35s'
    }
  },

  /**
   * Standard SEO - Pipeline équilibré pour usage quotidien
   */
  'standard-seo': {
    name: 'Standard SEO',
    description: 'Pipeline équilibré avec protection anti-détection standard',
    pipeline: [
      { step: 1, module: 'generation', mode: 'simple', intensity: 1.0 },
      { step: 2, module: 'selective', mode: 'standardEnhancement', intensity: 1.0 },
      { step: 3, module: 'adversarial', mode: 'light', intensity: 0.8, parameters: { detector: 'general', method: 'enhancement' } },
      { step: 4, module: 'human', mode: 'lightSimulation', intensity: 0.6 }
    ],
    metadata: {
      author: 'system',
      created: '2025-10-08',
      version: '1.0',
      tags: ['standard', 'seo', 'balanced'],
      estimatedDuration: '75s'
    }
  },

  /**
   * Premium SEO - Pipeline complet pour contenu premium
   */
  'premium-seo': {
    name: 'Premium SEO',
    description: 'Pipeline complet avec anti-détection avancée et qualité maximale',
    pipeline: [
      { step: 1, module: 'generation', mode: 'simple', intensity: 1.0 },
      { step: 2, module: 'selective', mode: 'fullEnhancement', intensity: 1.0, saveCheckpoint: true },
      { step: 3, module: 'adversarial', mode: 'standard', intensity: 1.0, parameters: { detector: 'general', method: 'regeneration' } },
      { step: 4, module: 'human', mode: 'standardSimulation', intensity: 0.8, parameters: { fatigueLevel: 0.5, errorRate: 0.3 } },
      { step: 5, module: 'pattern', mode: 'standardPatternBreaking', intensity: 0.9 },
      { step: 6, module: 'adversarial', mode: 'light', intensity: 0.7, parameters: { detector: 'general', method: 'enhancement' } }
    ],
    metadata: {
      author: 'system',
      created: '2025-10-08',
      version: '1.0',
      tags: ['premium', 'complete', 'quality'],
      estimatedDuration: '130s'
    }
  },

  /**
   * Heavy Guard - Protection maximale anti-détection
   */
  'heavy-guard': {
    name: 'Heavy Guard',
    description: 'Protection maximale avec multi-passes adversarial et human simulation',
    pipeline: [
      { step: 1, module: 'generation', mode: 'simple', intensity: 1.0 },
      { step: 2, module: 'selective', mode: 'fullEnhancement', intensity: 1.0 },
      { step: 3, module: 'adversarial', mode: 'heavy', intensity: 1.2, parameters: { detector: 'gptZero', method: 'regeneration' }, saveCheckpoint: true },
      { step: 4, module: 'human', mode: 'heavySimulation', intensity: 1.0, parameters: { fatigueLevel: 0.7, errorRate: 0.4 } },
      { step: 5, module: 'pattern', mode: 'heavyPatternBreaking', intensity: 1.0 },
      { step: 6, module: 'adversarial', mode: 'adaptive', intensity: 1.5, parameters: { detector: 'originality', method: 'hybrid' } },
      { step: 7, module: 'human', mode: 'personalityFocus', intensity: 1.3 },
      { step: 8, module: 'pattern', mode: 'syntaxFocus', intensity: 1.1 }
    ],
    metadata: {
      author: 'system',
      created: '2025-10-08',
      version: '1.0',
      tags: ['heavy', 'protection', 'anti-detection'],
      estimatedDuration: '180s'
    }
  },

  /**
   * Personality Focus - Mise en avant de la personnalité
   */
  'personality-focus': {
    name: 'Personality Focus',
    description: 'Pipeline optimisé pour un style personnel marqué',
    pipeline: [
      { step: 1, module: 'generation', mode: 'simple', intensity: 1.0 },
      { step: 2, module: 'selective', mode: 'personalityFocus', intensity: 1.2 },
      { step: 3, module: 'human', mode: 'personalityFocus', intensity: 1.5 },
      { step: 4, module: 'adversarial', mode: 'light', intensity: 0.6, parameters: { detector: 'general', method: 'enhancement' } }
    ],
    metadata: {
      author: 'system',
      created: '2025-10-08',
      version: '1.0',
      tags: ['personality', 'style', 'unique'],
      estimatedDuration: '70s'
    }
  },

  /**
   * Fluidity Master - Transitions et fluidité maximale
   */
  'fluidity-master': {
    name: 'Fluidity Master',
    description: 'Pipeline axé sur transitions fluides et connecteurs naturels',
    pipeline: [
      { step: 1, module: 'generation', mode: 'simple', intensity: 1.0 },
      { step: 2, module: 'selective', mode: 'fluidityFocus', intensity: 1.3 },
      { step: 3, module: 'pattern', mode: 'connectorsFocus', intensity: 1.2 },
      { step: 4, module: 'human', mode: 'standardSimulation', intensity: 0.7 }
    ],
    metadata: {
      author: 'system',
      created: '2025-10-08',
      version: '1.0',
      tags: ['fluidity', 'transitions', 'natural'],
      estimatedDuration: '73s'
    }
  },

  /**
   * Adaptive Smart - Pipeline intelligent avec modes adaptatifs
   */
  'adaptive-smart': {
    name: 'Adaptive Smart',
    description: 'Pipeline intelligent qui s\'adapte au contenu',
    pipeline: [
      { step: 1, module: 'generation', mode: 'simple', intensity: 1.0 },
      { step: 2, module: 'selective', mode: 'adaptive', intensity: 1.0 },
      { step: 3, module: 'adversarial', mode: 'adaptive', intensity: 1.0, parameters: { detector: 'general', method: 'hybrid' } },
      { step: 4, module: 'human', mode: 'adaptiveSimulation', intensity: 1.0 },
      { step: 5, module: 'pattern', mode: 'adaptivePatternBreaking', intensity: 1.0 }
    ],
    metadata: {
      author: 'system',
      created: '2025-10-08',
      version: '1.0',
      tags: ['adaptive', 'smart', 'intelligent'],
      estimatedDuration: '105s'
    }
  },

  /**
   * GPTZero Killer - Spécialisé anti-GPTZero
   */
  'gptzero-killer': {
    name: 'GPTZero Killer',
    description: 'Pipeline optimisé pour contourner GPTZero spécifiquement',
    pipeline: [
      { step: 1, module: 'generation', mode: 'simple', intensity: 1.0 },
      { step: 2, module: 'selective', mode: 'fullEnhancement', intensity: 1.0 },
      { step: 3, module: 'adversarial', mode: 'heavy', intensity: 1.5, parameters: { detector: 'gptZero', method: 'regeneration' } },
      { step: 4, module: 'human', mode: 'heavySimulation', intensity: 1.2 },
      { step: 5, module: 'pattern', mode: 'heavyPatternBreaking', intensity: 1.1 },
      { step: 6, module: 'adversarial', mode: 'standard', intensity: 1.0, parameters: { detector: 'gptZero', method: 'hybrid' } }
    ],
    metadata: {
      author: 'system',
      created: '2025-10-08',
      version: '1.0',
      tags: ['gptzero', 'anti-detection', 'specialized'],
      estimatedDuration: '155s'
    }
  },

  /**
   * Originality Bypass - Spécialisé anti-Originality.ai
   */
  'originality-bypass': {
    name: 'Originality Bypass',
    description: 'Pipeline optimisé pour contourner Originality.ai',
    pipeline: [
      { step: 1, module: 'generation', mode: 'simple', intensity: 1.0 },
      { step: 2, module: 'selective', mode: 'fullEnhancement', intensity: 1.0 },
      { step: 3, module: 'adversarial', mode: 'heavy', intensity: 1.4, parameters: { detector: 'originality', method: 'regeneration' } },
      { step: 4, module: 'human', mode: 'temporalFocus', intensity: 1.1 },
      { step: 5, module: 'pattern', mode: 'syntaxFocus', intensity: 1.2 },
      { step: 6, module: 'adversarial', mode: 'adaptive', intensity: 1.3, parameters: { detector: 'originality', method: 'hybrid' } }
    ],
    metadata: {
      author: 'system',
      created: '2025-10-08',
      version: '1.0',
      tags: ['originality', 'anti-detection', 'specialized'],
      estimatedDuration: '160s'
    }
  },

  /**
   * Minimal Test - Pipeline minimal pour tests rapides
   */
  'minimal-test': {
    name: 'Minimal Test',
    description: 'Pipeline minimal pour tests de connectivité et validation',
    pipeline: [
      { step: 1, module: 'generation', mode: 'simple', intensity: 1.0 }
    ],
    metadata: {
      author: 'system',
      created: '2025-10-08',
      version: '1.0',
      tags: ['test', 'minimal', 'debug'],
      estimatedDuration: '15s'
    }
  }
};

/**
 * Catégories de templates
 */
const CATEGORIES = {
  basic: ['minimal-test', 'light-fast'],
  standard: ['standard-seo', 'premium-seo'],
  advanced: ['heavy-guard', 'adaptive-smart'],
  specialized: ['gptzero-killer', 'originality-bypass'],
  focus: ['personality-focus', 'fluidity-master']
};

/**
 * Obtenir un template par nom
 */
function getTemplate(name) {
  return TEMPLATES[name] || null;
}

/**
 * Lister tous les templates
 */
function listTemplates() {
  return Object.entries(TEMPLATES).map(([key, template]) => ({
    id: key,
    name: template.name,
    description: template.description,
    steps: template.pipeline.length,
    tags: template.metadata.tags,
    estimatedDuration: template.metadata.estimatedDuration
  }));
}

/**
 * Lister templates par catégorie
 */
function listTemplatesByCategory(category) {
  const templateIds = CATEGORIES[category] || [];
  return templateIds.map(id => ({
    id,
    ...TEMPLATES[id]
  }));
}

/**
 * Obtenir toutes les catégories
 */
function getCategories() {
  return Object.entries(CATEGORIES).map(([name, templateIds]) => ({
    name,
    count: templateIds.length,
    templates: templateIds
  }));
}

/**
 * Rechercher templates par tag
 */
function searchByTag(tag) {
  return Object.entries(TEMPLATES)
    .filter(([_, template]) => template.metadata.tags.includes(tag))
    .map(([id, template]) => ({ id, ...template }));
}

module.exports = {
  TEMPLATES,
  CATEGORIES,
  getTemplate,
  listTemplates,
  listTemplatesByCategory,
  getCategories,
  searchByTag
};
