-- 渠道管理:统一企业微信/钉钉/飞书/通用 Webhook 渠道,入站消息经绑定
-- 模型应答后按平台协议回复。
CREATE TABLE IF NOT EXISTS gateway.channels (
    id uuid PRIMARY KEY,
    code text NOT NULL UNIQUE,
    name text NOT NULL,
    kind text NOT NULL CHECK (kind IN ('webhook', 'wecom', 'dingtalk', 'feishu')),
    encrypted_config bytea NOT NULL DEFAULT '',
    config_kek_version int NOT NULL DEFAULT 1,
    encrypted_api_key bytea NOT NULL DEFAULT '',
    api_key_kek_version int NOT NULL DEFAULT 1,
    model_binding jsonb NOT NULL DEFAULT '{}',
    enabled boolean NOT NULL DEFAULT true,
    created_by uuid,
    created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
    updated_at timestamptz NOT NULL DEFAULT clock_timestamp()
);
