<?php
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type");

require_once "../config/database.php";

try {
     = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASS);
    ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

     = ->prepare("SELECT * FROM tatkal_settings WHERE id = 1");
    ->execute();
     = ->fetch(PDO::FETCH_ASSOC);

    if (!) {
         = ->prepare("INSERT INTO tatkal_settings (is_enabled, price, max_slots_per_day, advance_booking_days, created_at) VALUES (1, 1500, 5, 7, NOW())");
        ->execute();
        
         = ->prepare("SELECT * FROM tatkal_settings WHERE id = 1");
        ->execute();
         = ->fetch(PDO::FETCH_ASSOC);
    }

    echo json_encode(["success" => true, "settings" => ]);

} catch (Exception ) {
    echo json_encode(["success" => false, "message" => "Error: " . ->getMessage()]);
}
?>
