<?php
require_once '../config/headers.php';
require_once '../config/database.php';
require_once '../utils/response.php';

if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
    sendResponse(405, 'error', 'Method not allowed');
}

$hotel_id = isset($_GET['hotel_id']) ? $_GET['hotel_id'] : '';

if (empty($hotel_id)) {
    sendResponse(400, 'error', 'Hotel ID is required');
}

$database = new Database();
$db = $database->getConnection();

try {
    // Fetch bookings specifically for this hotel
    $query = "
        SELECT * FROM hotel_bookings 
        WHERE hotel_id = :hotel_id 
        ORDER BY created_at DESC
    ";
    
    $stmt = $db->prepare($query);
    $stmt->execute([':hotel_id' => $hotel_id]);
    
    $bookings = $stmt->fetchAll(PDO::FETCH_ASSOC);

    sendResponse(200, 'success', 'Owner bookings fetched successfully', $bookings);
} catch (PDOException $e) {
    sendResponse(500, 'error', 'Database error: ' . $e->getMessage());
}
?>