-- [AC-IDMP-SHARE] 对话分享功能数据库迁移
-- 创建 shared_sessions 表，支持通过链接分享对话

-- 分享会话表
CREATE TABLE IF NOT EXISTS shared_sessions (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    share_token VARCHAR(255) NOT NULL UNIQUE,
    session_id VARCHAR(255) NOT NULL,
    tenant_id VARCHAR(255) NOT NULL,
    title VARCHAR(255),
    description TEXT,
    expires_at TIMESTAMP WITH TIME ZONE NOT NULL,
    is_active BOOLEAN DEFAULT TRUE,
    max_concurrent_users INTEGER DEFAULT 10,
    current_users INTEGER DEFAULT 0,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS ix_shared_sessions_share_token ON shared_sessions(share_token);
CREATE INDEX IF NOT EXISTS ix_shared_sessions_session_id ON shared_sessions(session_id);
CREATE INDEX IF NOT EXISTS ix_shared_sessions_tenant ON shared_sessions(tenant_id);
CREATE INDEX IF NOT EXISTS ix_shared_sessions_tenant_session ON shared_sessions(tenant_id, session_id);
CREATE INDEX IF NOT EXISTS ix_shared_sessions_expires_at ON shared_sessions(expires_at);
