CREATE TABLE anonymous_single_reservations (
  task_id UUID PRIMARY KEY,
  session_id VARCHAR(100) NOT NULL,
  client_ip INET NOT NULL,
  quota_date DATE NOT NULL,
  units INTEGER NOT NULL,
  status VARCHAR(20) NOT NULL DEFAULT 'pending',
  refund_after TIMESTAMPTZ NOT NULL DEFAULT (NOW() + INTERVAL '15 minutes'),
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  settled_at TIMESTAMPTZ,
  CONSTRAINT anonymous_single_reservations_units_check
    CHECK (units > 0),
  CONSTRAINT anonymous_single_reservations_status_check
    CHECK (status IN ('pending', 'charged', 'refund_pending', 'refunded'))
);

CREATE INDEX anonymous_single_reservations_unsettled
  ON anonymous_single_reservations(refund_after, created_at)
  WHERE status IN ('pending', 'refund_pending');
