<?php
// =====================================================
// Database Configuration
// =====================================================

define('DB_HOST', 'localhost');
define('DB_NAME', 'porihoqu_ticket');
define('DB_USER', 'porihoqu_ticket');
define('DB_PASS', ']78P*%Dt5^FVRf2B');

// Create connection
function getConnection()
{
    $conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    if ($conn->connect_error) {
        http_response_code(500);
        echo json_encode(["status" => "error", "message" => "Database connection failed"]);
        exit;
    }
    $conn->set_charset("utf8mb4");
    return $conn;
}

// Set JSON headers and CORS
function setHeaders()
{
    header("Content-Type: application/json; charset=UTF-8");
    header("Access-Control-Allow-Origin: *");
    header("Access-Control-Allow-Methods: GET, POST, DELETE, OPTIONS");
    header("Access-Control-Allow-Headers: Content-Type");

    if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
        http_response_code(200);
        exit;
    }
}

setHeaders();