<?php
// ─────────────────────────────────────────────────────────────
//  migrations/002_module_toggles.php
//  Creates sys_feature_toggles and seeds the three core modules.
//  Safe to run multiple times (IF NOT EXISTS + INSERT IGNORE).
// ─────────────────────────────────────────────────────────────
if (!defined('DB_HOST')) require_once dirname(__DIR__) . '/lib.php';

$pdo = db();

$pdo->exec("
    CREATE TABLE IF NOT EXISTS sys_feature_toggles (
        `key`        VARCHAR(64)  NOT NULL,
        label        VARCHAR(128) NOT NULL,
        description  TEXT,
        is_enabled   TINYINT(1)   NOT NULL DEFAULT 1,
        updated_at   DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP
                     ON UPDATE CURRENT_TIMESTAMP,
        PRIMARY KEY (`key`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
");

$pdo->exec("
    INSERT IGNORE INTO sys_feature_toggles (`key`, label, description, is_enabled) VALUES
    ('module_forms',
     'Form Builder',
     'Custom forms, submission inbox, file uploads, e-signatures, webhooks.',
     1),
    ('module_booking',
     'Appointment Booking',
     'Services, providers, schedules, slot availability and appointment management.',
     1),
    ('module_membership',
     'Membership & Sessions',
     'Stripe membership plans, session limits, QR check-in and access control.',
     1)
");

echo "Migration 002: sys_feature_toggles OK\n";
