-- ============================================================================================
-- PRODUCTION MIGRATION — Per-tenant meeting bot provider selection
-- ============================================================================================
-- One row per tenant, selecting which service dispatches a bot to join/record a meeting.
-- Attendee and Vexa (self-hosted, platform infrastructure) need no per-tenant credential.
-- Recall.ai / Skribby / MeetStream / MeetingBaaS (paid) let a tenant supply their own API key,
-- stored encrypted via the existing SecretDecryptionService (AES-256-GCM, same as
-- dim_mail_account.secret_encrypted) — never plaintext.
--
-- Idempotent — safe to re-run.
-- Deploy: mysql -u <user> -p `stacie_Aggie_v1.0` < db/tenant_meeting_bot_settings.sql
-- ============================================================================================

USE `stacie_Aggie_v1.0`;

CREATE TABLE IF NOT EXISTS tenant_meeting_bot_settings (
    id                  BIGINT AUTO_INCREMENT PRIMARY KEY,
    tenant_id           INT NOT NULL,
    provider            VARCHAR(20) NOT NULL DEFAULT 'attendee',
    api_key_encrypted   TEXT NULL,
    created_at          TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6),
    created_by          INT NULL,
    updated_at          TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    updated_by          INT NULL,
    is_deleted          TINYINT NOT NULL DEFAULT 0,
    UNIQUE KEY uq_tenant_bot_settings (tenant_id)
);
