-- S3/MCP/API integration configs; config_encrypted holds an AES-GCM encrypted JSON blob.

CREATE TABLE IF NOT EXISTS integration_configs (
    integration_config_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    integration_type      VARCHAR(32)  NOT NULL,
    name                  VARCHAR(255) NOT NULL,
    scope                 VARCHAR(32)  NOT NULL,
    owner_user_id         BIGINT,
    owner_team_id         BIGINT,
    enabled               BOOLEAN      NOT NULL DEFAULT TRUE,
    locked                BOOLEAN      NOT NULL DEFAULT FALSE,
    default_access        VARCHAR(32)  NOT NULL DEFAULT 'EXPLICIT_ONLY',
    config_encrypted      TEXT,
    created_at            TIMESTAMP    NOT NULL DEFAULT now(),
    updated_at            TIMESTAMP    NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_integration_configs_owner
    ON integration_configs (owner_user_id);

CREATE INDEX IF NOT EXISTS idx_integration_configs_type
    ON integration_configs (integration_type);

CREATE INDEX IF NOT EXISTS idx_integration_configs_scope
    ON integration_configs (scope);
