CREATE TABLE IF NOT EXISTS bookings (
    id INT PRIMARY KEY AUTO_INCREMENT,
    studio_id INT NOT NULL,
    service_id INT,
    client_name VARCHAR(255) NOT NULL,
    client_phone VARCHAR(50) NOT NULL,
    client_email VARCHAR(255),
    car_brand VARCHAR(100),
    car_model VARCHAR(100),
    car_year INT,
    preferred_date DATE,
    preferred_time TIME,
    message TEXT,
    status ENUM('new', 'confirmed', 'completed', 'cancelled') DEFAULT 'new',
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (studio_id) REFERENCES studios(id) ON DELETE CASCADE,
    FOREIGN KEY (service_id) REFERENCES studio_services(id) ON DELETE SET NULL,
    INDEX idx_studio (studio_id),
    INDEX idx_status (status),
    INDEX idx_date (preferred_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
