<?php
namespace App\Controllers;

require_once BASE_PATH . '/app/helpers/conference_scope.php';

use App\Core\Controller;
use App\Core\Database;

class ConferenceActivationController extends Controller
{
    public function activate($id)
    {
        if (!in_array($_SESSION['user']['role'], ['org_admin','super_admin'])) {
            http_response_code(403);
            exit('Forbidden');
        }

        $db = Database::getInstance();

        // Get org_id of target conference
        $stmt = $db->prepare("SELECT org_id FROM conferences WHERE id = ?");
        $stmt->execute([$id]);
        $conf = $stmt->fetch();

        if (!$conf) {
            exit('Conference not found');
        }

        $orgId = $conf['org_id'];

        // Deactivate all conferences in this org
        $db->prepare("
            UPDATE conferences 
            SET is_active = 0 
            WHERE org_id = ?
        ")->execute([$orgId]);

        // Activate selected one
        $db->prepare("
            UPDATE conferences 
            SET is_active = 1 
            WHERE id = ?
        ")->execute([$id]);

        echo "Conference activated successfully.";
    }
}
