<?php
require_once 'config.php';

try {
    $pdo = getDBConnection();

    // Create ships table
    $sql = "CREATE TABLE IF NOT EXISTS `ships` (
      `ship_id` varchar(50) NOT NULL,
      `name` varchar(100) NOT NULL,
      `max_temp` decimal(5,2) DEFAULT 25.00,
      PRIMARY KEY (`ship_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;";

    $pdo->exec($sql);
    echo "Table 'ships' created successfully.\n";

    // Insert default ship if not exists
    $stmt = $pdo->prepare("INSERT IGNORE INTO ships (ship_id, name, max_temp) VALUES (?, ?, ?)");
    $stmt->execute(['BUQUE-01', 'Buque 01', 25.0]);
    echo "Default ship 'BUQUE-01' inserted.\n";

} catch (PDOException $e) {
    die("Error: " . $e->getMessage());
}
?>