#!/usr/bin/env php
<?php
/**
 * Seed Sample Data
 * Populates database with sample data for testing
 */

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

$pdo = getDB();

echo "Seeding sample data...\n";

// Create admin user
$adminHash = password_hash('admin123', PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (username, email, full_name, password_hash, role, is_active) 
                      VALUES (?, ?, ?, ?, 'admin', 1)
                      ON DUPLICATE KEY UPDATE id=id");
$stmt->execute(['admin', 'admin@homoeopathy.com', 'System Administrator', $adminHash]);
echo "✓ Admin user created (admin/admin123)\n";

// Create sample doctor
$doctorHash = password_hash('doctor123', PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (username, email, full_name, password_hash, role, is_active) 
                      VALUES (?, ?, ?, ?, 'doctor', 1)
                      ON DUPLICATE KEY UPDATE id=id");
$stmt->execute(['doctor', 'doctor@homoeopathy.com', 'Dr. Sample', $doctorHash]);
$doctorId = $pdo->lastInsertId();
echo "✓ Sample doctor created (doctor/doctor123)\n";

// Create sample subscription
$stmt = $pdo->prepare("INSERT INTO subscriptions (user_id, plan_type, start_date, end_date, amount, is_active) 
                      VALUES (?, '1year', CURDATE(), DATE_ADD(CURDATE(), INTERVAL 365 DAY), 99.99, 1)
                      ON DUPLICATE KEY UPDATE id=id");
$stmt->execute([$doctorId]);
echo "✓ Sample subscription created\n";

// Sample remedies
$remedies = [
    ['Sulphur', 'Sulph', 'Great remedy for chronic diseases. Skin affections, burning sensations. Worse from warmth, bathing. Better from open air, cold drinks.'],
    ['Lycopodium', 'Lyc', 'Digestive complaints, right-sided symptoms. Worse 4-8 PM. Craves sweets, warm food. Better from warm food, uncovering.'],
    ['Arsenicum Album', 'Ars', 'Anxiety, restlessness, burning pains. Worse midnight, cold, wet weather. Better warm drinks, warmth.'],
    ['Pulsatilla', 'Puls', 'Changeable symptoms, mild disposition. Worse warm rooms, rich food. Better open air, cold applications.'],
    ['Nux Vomica', 'Nux', 'Irritable, oversensitive, digestive issues. Worse morning, mental exertion. Better sleep, strong pressure.'],
    ['Belladonna', 'Bell', 'Sudden onset, throbbing pains, redness. Worse light, noise, touch. Better rest, semi-erect position.'],
    ['Calcarea Carbonica', 'Calc', 'Slow, fat, chilly. Worse cold, wet weather, exertion. Better dry climate, lying down.'],
    ['Ignatia', 'Ign', 'Hysterical, contradictory emotions. Worse grief, coffee, tobacco. Better distraction, company.'],
    ['Natrum Muriaticum', 'Nat-m', 'Closed, reserved, sensitive. Worse consolation, sun, heat. Better open air, sweating.'],
    ['Sepia', 'Sep', 'Indifferent, averse to family. Worse pregnancy, hormonal changes. Better vigorous exercise, sleep.']
];

foreach ($remedies as $remedy) {
    $stmt = $pdo->prepare("INSERT INTO remedies (name, abbreviation, materia_medica_text) 
                          VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE name=name");
    $stmt->execute($remedy);
}
echo "✓ " . count($remedies) . " sample remedies added\n";

// Sample chapters
$chapters = ['MIND', 'VERTIGO', 'HEAD', 'EYE', 'EAR', 'NOSE', 'FACE', 'MOUTH', 'STOMACH', 'ABDOMEN'];
foreach ($chapters as $chapter) {
    $stmt = $pdo->prepare("INSERT INTO rubrics (chapter_name, rubric_name, full_path, level) 
                          VALUES (?, ?, ?, 1) ON DUPLICATE KEY UPDATE id=id");
    $stmt->execute([$chapter, $chapter, $chapter]);
}
echo "✓ " . count($chapters) . " sample chapters added\n";

// Sample case
$stmt = $pdo->prepare("INSERT INTO cases (user_id, patient_name, patient_mobile, patient_age, patient_gender, 
                      chief_complaint, case_history, status) 
                      VALUES (?, 'John Doe', '9876543210', 35, 'M', 'Headache for 3 days', 'History of migraines', 'active')");
$stmt->execute([$doctorId]);
echo "✓ Sample case created\n";

echo "\n============================================\n";
echo "Sample data seeded successfully!\n";
echo "============================================\n";
echo "Admin Login: admin / admin123\n";
echo "Doctor Login: doctor / doctor123\n";