-- MSIN-4424 — Autoriser les mêmes numéros de dossard entre épreuves (réglage événement)
-- Idempotent. Exécuter avant déploiement PHP/JS.

SET @db := DATABASE();

SET @col_exists := (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = @db
      AND TABLE_NAME = 'inscriptions_evenements'
      AND COLUMN_NAME = 'eve_bib_allow_inter_epr'
);

SET @sql_col := IF(
    @col_exists = 0,
    'ALTER TABLE inscriptions_evenements ADD COLUMN eve_bib_allow_inter_epr TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT ''MSIN-4424 — 1 = mêmes no_bib autorisés entre épreuves'' AFTER eve_epreuve_modifiable',
    'SELECT ''eve_bib_allow_inter_epr already exists'' AS note'
);

PREPARE stmt_col FROM @sql_col;
EXECUTE stmt_col;
DEALLOCATE PREPARE stmt_col;

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_allow_inter_epr', 'fr', 'Autoriser les mêmes numéros de dossard entre épreuves', 'Permet d''utiliser les mêmes numéros sur plusieurs épreuves (ex. 5 km et 10 km). Les doublons à l''intérieur d''une même épreuve restent interdits.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_allow_inter_epr' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_allow_inter_epr', 'en', 'Allow the same bib numbers across races', 'Lets multiple races share the same bib numbers (e.g. 5K and 10K). Duplicates within a single race remain forbidden.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_allow_inter_epr' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_anomalies_inter_epr_dupes_title', 'fr', 'Dossards en double entre épreuves', 'Même numéro de dossard utilisé sur plus d''une épreuve alors que l''option n''est pas activée.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_anomalies_inter_epr_dupes_title' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_anomalies_inter_epr_dupes_title', 'en', 'Duplicate bibs across races', 'Same bib number used on more than one race while the option is disabled.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_anomalies_inter_epr_dupes_title' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_event_config_inter_epr_on', 'fr', 'Inter épreuve', 'Indique que les mêmes numéros de dossard sont autorisés entre épreuves.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_event_config_inter_epr_on' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_event_config_inter_epr_on', 'en', 'Inter-race', 'Indicates that the same bib numbers are allowed across races.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_event_config_inter_epr_on' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_event_config_title', 'fr', 'Configuration globale pour l''assignation de dossard', 'Réglages applicables à tout l''événement (ex. autorisation des mêmes numéros entre épreuves).', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_event_config_title' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_event_config_title', 'en', 'Global bib assignment settings', 'Settings that apply to the whole event (e.g. allowing the same numbers across races).', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_event_config_title' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_title', 'fr', 'Sommaire des quantités', 'Vue d''ensemble des dossards à assigner, restants et orphelins pour toutes les épreuves.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_title' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_title', 'en', 'Quantity summary', 'Overview of bibs to assign, remaining and orphans across all races.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_title' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_a_assigner', 'fr', 'À assigner', 'Participants sans dossard, éligibles à l''assignation par lot.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_a_assigner' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_a_assigner', 'en', 'To assign', 'Participants without a bib, eligible for batch assignment.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_a_assigner' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_bib_restant', 'fr', 'Dossards restants', 'Numéros encore libres dans les séquences configurées.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_bib_restant' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_bib_restant', 'en', 'Bibs remaining', 'Numbers still free in configured sequences.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_bib_restant' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_orphelins', 'fr', 'Personnes orphelines', 'Dossards assignés à des participants annulés ou d''une autre épreuve.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_orphelins' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_orphelins', 'en', 'Orphan participants', 'Bibs assigned to cancelled participants or from another race.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_orphelins' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_total', 'fr', 'Inscrits', 'Nombre total de participants actifs.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_total' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_total', 'en', 'Registered', 'Total number of active participants.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_total' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_avec_bib', 'fr', 'Avec dossard', 'Participants ayant déjà un numéro de dossard.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_avec_bib' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_avec_bib', 'en', 'With bib', 'Participants who already have a bib number.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_avec_bib' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_sans_bib', 'fr', 'Sans dossard', 'Participants actifs sans numéro de dossard.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_sans_bib' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_sans_bib', 'en', 'Without bib', 'Active participants without a bib number.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_sans_bib' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_places_dispo', 'fr', 'Places disponibles', 'Places d''inscription encore disponibles par épreuve.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_places_dispo' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_places_dispo', 'en', 'Places available', 'Registration spots still available per race.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_places_dispo' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_global', 'fr', 'Total événement', 'Somme des quantités pour toutes les épreuves actives.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_global' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_global', 'en', 'Event total', 'Sum of quantities for all active races.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_global' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_by_epr', 'fr', 'Détail par épreuve', 'Répartition des quantités pour chaque épreuve.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_by_epr' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_by_epr', 'en', 'Breakdown by race', 'Quantity breakdown for each race.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_by_epr' AND info_langue = 'en' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_col_epr', 'fr', 'Épreuve', 'Nom de l''épreuve.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_col_epr' AND info_langue = 'fr' AND info_prg = 'compte.php');

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation)
SELECT 'bib_v4_qty_summary_col_epr', 'en', 'Race', 'Race name.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_qty_summary_col_epr' AND info_langue = 'en' AND info_prg = 'compte.php');
