<?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");

if ($_SERVER["REQUEST_METHOD"] === "OPTIONS") {
    exit(0);
}

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

try {
    $pdo = getDBConnection();
    
    // Clear existing consultation types
    $pdo->exec("DELETE FROM consultation_types");
    
    // Insert all consultation types
    $pdo->exec("
        INSERT INTO consultation_types (type_name, type_code, base_price, description, is_active) VALUES
        ('Office Meeting', 'office_meeting', 100.00, 'In-person consultation at office', 1),
        ('Video Call', 'video_call', 500.00, 'Online video consultation via video call', 1),
        ('Audio Call', 'audio_call', 400.00, 'Online audio consultation via phone call', 1),
        ('Tatkal Booking', 'tatkal_booking', 1500.00, 'Emergency/urgent consultation booking', 1)
    ");
    
    // Get all consultation types
    $stmt = $pdo->prepare("SELECT * FROM consultation_types ORDER BY id ASC");
    $stmt->execute();
    $types = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo json_encode([
        "success" => true,
        "message" => "Consultation types fixed successfully",
        "consultation_types" => $types
    ]);
    
} catch (Exception $e) {
    echo json_encode([
        "success" => false,
        "message" => "Error: " . $e->getMessage()
    ]);
}
?>
