/**
 * Project Templates — Pre-defined workflow trees for common service orders.
 *
 * Each template defines a sequence of Dispatch Job steps that get created
 * together when applied to a ticket. Steps can have:
 *   - subject, job_type, priority, duration_h
 *   - assigned_group: which team/group handles it
 *   - depends_on_step: index (0-based) of the step this one depends on
 *   - on_open_webhook / on_close_webhook: n8n webhook URLs fired on status change
 *
 * Templates are stored in the frontend for now. Future: sync to ERPNext
 * "Dispatch Template" doctype for admin management.
 */

export const PROJECT_TEMPLATES = [
  {
    id: 'phone_service',
    name: 'Service téléphonique résidentiel',
    icon: 'phone_in_talk',
    description: 'Importation du numéro, installation fibre, portage du numéro',
    category: 'Téléphonie',
    steps: [
      {
        merge_key: 'port_phone_request',
        subject: 'Importer le numéro de téléphone',
        job_type: 'Autre',
        priority: 'medium',
        duration_h: 0.5,
        assigned_group: 'Admin',
        depends_on_step: null,
        on_open_webhook: '',
        on_close_webhook: '',
      },
      {
        merge_key: 'fiber_install_visit',
        subject: 'Installation fibre chez le client',
        job_type: 'Installation',
        priority: 'high',
        duration_h: 3,
        assigned_group: 'Tech Targo',
        depends_on_step: 0,
        on_open_webhook: '',
        on_close_webhook: '',
      },
      {
        merge_key: 'port_phone_execute',
        subject: 'Portage du numéro vers Gigafibre',
        job_type: 'Autre',
        priority: 'medium',
        duration_h: 0.5,
        assigned_group: 'Admin',
        depends_on_step: 1,
        on_open_webhook: '',
        on_close_webhook: '',
      },
      {
        merge_key: 'phone_service_test',
        subject: 'Validation et test du service téléphonique',
        job_type: 'Dépannage',
        priority: 'medium',
        duration_h: 0.5,
        assigned_group: 'Tech Targo',
        depends_on_step: 2,
        on_open_webhook: '',
        on_close_webhook: '',
      },
    ],
  },
  {
    id: 'fiber_install',
    name: 'Installation fibre résidentielle',
    icon: 'cable',
    description: 'Vérification pré-install, installation, activation, test de débit',
    category: 'Internet',
    steps: [
      {
        merge_key: 'fiber_pre_check',
        subject: 'Vérification pré-installation (éligibilité & OLT)',
        job_type: 'Autre',
        priority: 'medium',
        duration_h: 0.5,
        assigned_group: 'Admin',
        depends_on_step: null,
        on_open_webhook: '',
        on_close_webhook: '',
      },
      {
        merge_key: 'fiber_install_visit',
        subject: 'Installation fibre chez le client',
        job_type: 'Installation',
        priority: 'high',
        duration_h: 3,
        assigned_group: 'Tech Targo',
        depends_on_step: 0,
        on_open_webhook: '',
        on_close_webhook: '',
      },
      {
        merge_key: 'fiber_activation',
        subject: 'Activation du service & configuration ONT',
        job_type: 'Installation',
        priority: 'high',
        duration_h: 0.5,
        assigned_group: 'Admin',
        depends_on_step: 1,
        on_open_webhook: '',
        on_close_webhook: '',
      },
      {
        merge_key: 'fiber_speed_test',
        subject: 'Test de débit & validation client',
        job_type: 'Dépannage',
        priority: 'medium',
        duration_h: 0.5,
        assigned_group: 'Tech Targo',
        depends_on_step: 2,
        on_open_webhook: '',
        on_close_webhook: '',
      },
    ],
  },
  {
    id: 'move_service',
    name: 'Déménagement de service',
    icon: 'local_shipping',
    description: 'Retrait ancien site, installation nouveau site, transfert abonnement',
    category: 'Déménagement',
    steps: [
      {
        merge_key: 'move_prep',
        subject: 'Préparation déménagement (vérifier éligibilité nouveau site)',
        job_type: 'Autre',
        priority: 'medium',
        duration_h: 0.5,
        assigned_group: 'Admin',
        depends_on_step: null,
        on_open_webhook: '',
        on_close_webhook: '',
      },
      {
        merge_key: 'move_removal',
        subject: 'Retrait équipement ancien site',
        job_type: 'Retrait',
        priority: 'medium',
        duration_h: 1,
        assigned_group: 'Tech Targo',
        depends_on_step: 0,
        on_open_webhook: '',
        on_close_webhook: '',
      },
      {
        merge_key: 'fiber_install_visit',
        subject: 'Installation au nouveau site',
        job_type: 'Installation',
        priority: 'high',
        duration_h: 3,
        assigned_group: 'Tech Targo',
        depends_on_step: 1,
        on_open_webhook: '',
        on_close_webhook: '',
      },
      {
        merge_key: 'move_transfer',
        subject: 'Transfert abonnement & mise à jour adresse',
        job_type: 'Autre',
        priority: 'medium',
        duration_h: 0.5,
        assigned_group: 'Admin',
        depends_on_step: 2,
        on_open_webhook: '',
        on_close_webhook: '',
      },
    ],
  },
  {
    id: 'repair_service',
    name: 'Réparation service client',
    icon: 'build',
    description: 'Diagnostic, intervention terrain, validation',
    category: 'Support',
    steps: [
      {
        merge_key: 'repair_diag',
        subject: 'Diagnostic à distance',
        job_type: 'Dépannage',
        priority: 'high',
        duration_h: 0.5,
        assigned_group: 'Admin',
        depends_on_step: null,
        on_open_webhook: '',
        on_close_webhook: '',
      },
      {
        merge_key: 'repair_visit',
        subject: 'Intervention terrain',
        job_type: 'Réparation',
        priority: 'high',
        duration_h: 2,
        assigned_group: 'Tech Targo',
        depends_on_step: 0,
        on_open_webhook: '',
        on_close_webhook: '',
      },
      {
        merge_key: 'repair_validate',
        subject: 'Validation & suivi client',
        job_type: 'Dépannage',
        priority: 'medium',
        duration_h: 0.5,
        assigned_group: 'Admin',
        depends_on_step: 1,
        on_open_webhook: '',
        on_close_webhook: '',
      },
    ],
  },
]

export const ASSIGNED_GROUPS = [
  'Admin',
  'Tech Targo',
  'Support',
  'NOC',
  'Facturation',
]
