<?php

require_once __DIR__ . '/../config/database.php';

$workspace_id = $_GET['workspace_id'] ?? '';

if (empty($workspace_id)) {
    echo "Missing workspace_id";
    exit;
}

$sql = "INSERT INTO questions (
    workspace_id,
    source_type,
    title,
    stem,
    lead_in,
    option_a,
    option_b,
    option_c,
    option_d,
    option_e,
    correct_answer,
    correct_answer_letter,
    justification,
    specialty,
    condition_name,
    presentation,
    skill,
    year_level,
    tags,
    status
) VALUES (
    :workspace_id,
    :source_type,
    :title,
    :stem,
    :lead_in,
    :option_a,
    :option_b,
    :option_c,
    :option_d,
    :option_e,
    :correct_answer,
    :correct_answer_letter,
    :justification,
    :specialty,
    :condition_name,
    :presentation,
    :skill,
    :year_level,
    :tags,
    :status
)";

$stmt = $pdo->prepare($sql);

$stmt->execute([
    'workspace_id' => $workspace_id,
    'source_type' => 'generated',
    'title' => 'Test SBA Question',
    'stem' => 'A 45-year-old man presents with wheeze and shortness of breath. He has a history of asthma.',
    'lead_in' => 'What is the most likely diagnosis?',
    'option_a' => 'Pneumonia',
    'option_b' => 'Asthma exacerbation',
    'option_c' => 'Pulmonary embolism',
    'option_d' => 'Heart failure',
    'option_e' => 'Pneumothorax',
    'correct_answer' => 'Asthma exacerbation',
    'correct_answer_letter' => 'B',
    'justification' => 'The history of wheeze, breathlessness and known asthma makes asthma exacerbation the best answer.',
    'specialty' => 'Respiratory Medicine',
    'condition_name' => 'Asthma',
    'presentation' => 'Wheeze',
    'skill' => 'Diagnosis',
    'year_level' => 4,
    'tags' => 'respiratory,asthma,diagnosis',
    'status' => 'Draft'
]);

echo "Test question inserted successfully for workspace: " . $workspace_id;