-- MSIN-4512 — PDF distribution : option inclure inscrits sans numéro de dossard
-- Prérequis : sql/MSIN-4512-dist-print-colonnes-base.sql
-- Notes : exécution UNIQUEMENT sur dev préprod ; autres env = Navicat structure + sync_static_db

SET @db := DATABASE();

-- Flag par épreuve (0 = seulement avec no_bib, 1 = inclure aussi sans numéro)
SET @col_include := (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'inscriptions_epreuves' AND COLUMN_NAME = 'ba_bib_dist_include_sans_bib'
);
SET @sql_include := IF(
    @col_include = 0,
    'ALTER TABLE inscriptions_epreuves ADD COLUMN ba_bib_dist_include_sans_bib TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT ''MSIN-4512 — 1 = PDF dist inclut inscrits sans no_bib'' AFTER ba_bib_dist_cols',
    'SELECT ''ba_bib_dist_include_sans_bib already exists'' AS note'
);
PREPARE stmt_include FROM @sql_include;
EXECUTE stmt_include;
DEALLOCATE PREPARE stmt_include;

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_dist_print_include_sans_bib', 'fr', 'Inclure les inscrits sans numéro de dossard', 'Ajoute sur le PDF de cette épreuve les inscrits actifs qui n''ont pas encore de numéro. La colonne dossard reste vide pour eux.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_dist_print_include_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_dist_print_include_sans_bib', 'en', 'Include registrations without a bib number', 'Adds active registrations that do not yet have a bib number to this race PDF. The bib column stays empty for them.', 'compte.php', '', 0, 1, '', '', '', NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM info WHERE info_clef = 'bib_v4_dist_print_include_sans_bib' AND info_langue = 'en' AND info_prg = 'compte.php');
