-- depends_on: room
CREATE TABLE IF NOT EXISTS dm_conversation (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    room UUID NOT NULL REFERENCES room(id) ON DELETE CASCADE,
    initiator UUID NOT NULL,
    recipient UUID NOT NULL,
    is_closed BOOLEAN NOT NULL DEFAULT FALSE,
    closed_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    UNIQUE (initiator, recipient),
    CHECK (initiator < recipient)
);

CREATE INDEX IF NOT EXISTS idx_dm_conversation_room ON dm_conversation (room);
CREATE INDEX IF NOT EXISTS idx_dm_conversation_initiator ON dm_conversation (initiator);
CREATE INDEX IF NOT EXISTS idx_dm_conversation_recipient ON dm_conversation (recipient);
