-- Migration 010 — booking_guests: per-booking guest roster with documents

CREATE TABLE IF NOT EXISTS booking_guests (
  id                   UUID         PRIMARY KEY DEFAULT gen_random_uuid(),
  booking_id           UUID         NOT NULL REFERENCES bookings(id) ON DELETE CASCADE,
  hotel_id             UUID         NOT NULL REFERENCES hotels(id) ON DELETE CASCADE,
  guest_id             UUID         REFERENCES guests(id) ON DELETE SET NULL,

  first_name           VARCHAR(100) NOT NULL,
  last_name            VARCHAR(100) NOT NULL,
  middle_name          VARCHAR(100),

  birth_date           DATE,
  is_child             BOOLEAN      NOT NULL DEFAULT false,
  is_main              BOOLEAN      NOT NULL DEFAULT false,

  passport_series      VARCHAR(20),
  passport_number      VARCHAR(20),
  passport_issued_by   TEXT,
  passport_issue_date  DATE,
  nationality          VARCHAR(100),

  created_at           TIMESTAMPTZ  NOT NULL DEFAULT NOW(),
  updated_at           TIMESTAMPTZ  NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_booking_guests_booking ON booking_guests(booking_id);
CREATE INDEX IF NOT EXISTS idx_booking_guests_guest   ON booking_guests(guest_id);
