-- Migration: Add Teams accounts table for Microsoft Teams Bot integration
-- Run this in Supabase SQL editor before deploying Teams bot feature

CREATE TABLE teams_accounts (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES profiles(id) ON DELETE CASCADE,
    teams_user_id TEXT,
    teams_tenant_id TEXT,
    teams_service_url TEXT NOT NULL,
    teams_conversation_id TEXT NOT NULL,
    is_active BOOLEAN NOT NULL DEFAULT TRUE,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    CONSTRAINT teams_accounts_user_id_unique UNIQUE (user_id)
);

CREATE INDEX idx_teams_accounts_user_id ON teams_accounts (user_id);
