<?php
require_once '../config.php';

echo "<h1>Setting up Contacts Table...</h1>";

try {
    // Contacts Table
    $sql = "CREATE TABLE IF NOT EXISTS `contacts` (
      `id` INT AUTO_INCREMENT PRIMARY KEY,
      `user_id` INT NOT NULL,
      `phone_number` VARCHAR(20) NOT NULL,
      `name` VARCHAR(100) DEFAULT NULL,
      `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      INDEX `idx_user_phone` (`user_id`, `phone_number`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";

    $pdo->exec($sql);
    echo "Table 'contacts' created or already exists.<br>";
    echo "<h3 style='color:green'>Database Setup Complete!</h3>";

} catch (PDOException $e) {
    echo "<h3 style='color:red'>Error: " . $e->getMessage() . "</h3>";
}
?>