CREATE TABLE hotel_deposit_settings (
  hotel_id UUID PRIMARY KEY REFERENCES hotels(id) ON DELETE CASCADE,
  is_enabled BOOLEAN NOT NULL DEFAULT false,
  amount NUMERIC(10,2) NOT NULL DEFAULT 5000,
  yookassa_shop_id TEXT,
  yookassa_secret_key TEXT,
  updated_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE TABLE booking_deposits (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  hotel_id UUID NOT NULL REFERENCES hotels(id),
  booking_id UUID NOT NULL REFERENCES bookings(id),
  amount NUMERIC(10,2) NOT NULL,
  status TEXT NOT NULL DEFAULT 'pending',
  -- pending = ожидает оплаты
  -- paid_cash = оплачен наличными
  -- hold_created = холд создан в ЮКасса
  -- hold_confirmed = холд подтверждён (webhook)
  -- captured = частично/полностью списано
  -- refunded = возвращён полностью
  -- cancelled = отменён
  payment_method TEXT, -- 'cash', 'yookassa_hold'
  yookassa_payment_id TEXT,
  yookassa_confirmation_url TEXT,
  captured_amount NUMERIC(10,2),
  retention_reason TEXT,
  guest_email_sent BOOLEAN NOT NULL DEFAULT false,
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  paid_at TIMESTAMPTZ,
  released_at TIMESTAMPTZ
);

CREATE INDEX ON booking_deposits(booking_id);
