-- Script SQL pour initialiser les 3 plans tarifaires Izibrick
-- Exécuter avec : mysql -u root -p izibrick < migrations/init_subscription_plans.sql

-- Supprimer les plans existants (optionnel, pour réinitialisation propre)
-- DELETE FROM fir_subscription_plan WHERE code IN ('starter', 'basic', 'pro');

-- Insertion du plan STARTER (Gratuit)
INSERT INTO fir_subscription_plan (
    name,
    code,
    description,
    price_monthly,
    price_yearly,
    currency,
    max_sites,
    max_pages,
    max_storage,
    custom_domain,
    remove_watermark,
    priority_support,
    ai_generation,
    has_ads,
    features,
    is_active,
    display_order,
    created_at,
    updated_at
) VALUES (
    'Starter',
    'starter',
    'Plan gratuit pour découvrir Izibrick. Idéal pour tester la plateforme avec des fonctionnalités de base.',
    '0.00',
    '0.00',
    'EUR',
    1,
    5,
    100,
    0,
    0,
    0,
    0,
    1,
    '["1 site","5 pages maximum","100 MB de stockage","Sous-domaine Izibrick","Avec watermark","Publicité Izibrick","Widgets limités","Support standard (72h)"]',
    1,
    1,
    NOW(),
    NOW()
) ON DUPLICATE KEY UPDATE
    name = VALUES(name),
    description = VALUES(description),
    price_monthly = VALUES(price_monthly),
    price_yearly = VALUES(price_yearly),
    max_sites = VALUES(max_sites),
    max_pages = VALUES(max_pages),
    max_storage = VALUES(max_storage),
    custom_domain = VALUES(custom_domain),
    remove_watermark = VALUES(remove_watermark),
    priority_support = VALUES(priority_support),
    ai_generation = VALUES(ai_generation),
    has_ads = VALUES(has_ads),
    features = VALUES(features),
    is_active = VALUES(is_active),
    display_order = VALUES(display_order),
    updated_at = NOW();

-- Insertion du plan BASIC (9,90€/mois)
INSERT INTO fir_subscription_plan (
    name,
    code,
    description,
    price_monthly,
    price_yearly,
    currency,
    max_sites,
    max_pages,
    max_storage,
    custom_domain,
    remove_watermark,
    priority_support,
    ai_generation,
    has_ads,
    features,
    is_active,
    display_order,
    created_at,
    updated_at
) VALUES (
    'Basic',
    'basic',
    'Plan idéal pour les petites entreprises et indépendants. Toutes les fonctionnalités essentielles pour un site professionnel.',
    '9.90',
    '99.00',
    'EUR',
    1,
    9999,
    5120,
    1,
    1,
    0,
    0,
    0,
    '["1 site professionnel","Pages illimitées","5 GB de stockage","Domaine personnalisé inclus","Sans watermark","Sans publicité","Tous les widgets","Statistiques de visite","SSL automatique","Support email (48h)","Sauvegarde hebdomadaire"]',
    1,
    2,
    NOW(),
    NOW()
) ON DUPLICATE KEY UPDATE
    name = VALUES(name),
    description = VALUES(description),
    price_monthly = VALUES(price_monthly),
    price_yearly = VALUES(price_yearly),
    max_sites = VALUES(max_sites),
    max_pages = VALUES(max_pages),
    max_storage = VALUES(max_storage),
    custom_domain = VALUES(custom_domain),
    remove_watermark = VALUES(remove_watermark),
    priority_support = VALUES(priority_support),
    ai_generation = VALUES(ai_generation),
    has_ads = VALUES(has_ads),
    features = VALUES(features),
    is_active = VALUES(is_active),
    display_order = VALUES(display_order),
    updated_at = NOW();

-- Insertion du plan PRO (24,90€/mois)
INSERT INTO fir_subscription_plan (
    name,
    code,
    description,
    price_monthly,
    price_yearly,
    currency,
    max_sites,
    max_pages,
    max_storage,
    custom_domain,
    remove_watermark,
    priority_support,
    ai_generation,
    has_ads,
    features,
    is_active,
    display_order,
    created_at,
    updated_at
) VALUES (
    'Pro',
    'pro',
    'Plan professionnel pour agences et entrepreneurs. Inclut IA, e-commerce et gestion multi-sites.',
    '24.90',
    '249.00',
    'EUR',
    3,
    9999,
    25600,
    1,
    1,
    1,
    1,
    0,
    '["3 sites","Pages illimitées","25 GB de stockage","Domaines personnalisés illimités","Sans watermark","Génération IA de contenu (50/mois)","Chat IA sur le site","E-commerce activable","Gestion multi-utilisateurs","Support prioritaire (24h)","Statistiques avancées","Google Analytics","Sauvegarde quotidienne","Export de données","Assistance à la création"]',
    1,
    3,
    NOW(),
    NOW()
) ON DUPLICATE KEY UPDATE
    name = VALUES(name),
    description = VALUES(description),
    price_monthly = VALUES(price_monthly),
    price_yearly = VALUES(price_yearly),
    max_sites = VALUES(max_sites),
    max_pages = VALUES(max_pages),
    max_storage = VALUES(max_storage),
    custom_domain = VALUES(custom_domain),
    remove_watermark = VALUES(remove_watermark),
    priority_support = VALUES(priority_support),
    ai_generation = VALUES(ai_generation),
    has_ads = VALUES(has_ads),
    features = VALUES(features),
    is_active = VALUES(is_active),
    display_order = VALUES(display_order),
    updated_at = NOW();

-- Afficher les plans créés
SELECT
    id,
    name,
    code,
    CONCAT(price_monthly, '€') as prix_mensuel,
    CONCAT(price_yearly, '€') as prix_annuel,
    max_sites as sites,
    max_pages as pages,
    CONCAT(ROUND(max_storage / 1024, 2), ' GB') as stockage,
    IF(has_ads = 1, 'Oui', 'Non') as publicite,
    IF(is_active = 1, 'Actif', 'Inactif') as statut
FROM fir_subscription_plan
WHERE code IN ('starter', 'basic', 'pro')
ORDER BY display_order;
