-- Agent 与 Workflow 能力绑定表。

CREATE TABLE IF NOT EXISTS agent_capability_binding (
    id BIGSERIAL PRIMARY KEY,
    owner_type VARCHAR(50) NOT NULL,
    owner_id BIGINT NOT NULL,
    capability_type VARCHAR(50) NOT NULL,
    capability_id BIGINT NOT NULL,
    enabled BOOLEAN NOT NULL DEFAULT TRUE,
    config_json JSONB NOT NULL DEFAULT '{}'::jsonb,
    version INTEGER NOT NULL DEFAULT 1,
    create_time TIMESTAMP,
    update_time TIMESTAMP,
    remark VARCHAR(500) DEFAULT '',
    create_by VARCHAR(64),
    update_by VARCHAR(64),
    CONSTRAINT uk_agent_capability_binding UNIQUE (owner_type, owner_id, capability_type, capability_id)
);

CREATE INDEX IF NOT EXISTS idx_agent_capability_owner ON agent_capability_binding (owner_type, owner_id);
CREATE INDEX IF NOT EXISTS idx_agent_capability_type ON agent_capability_binding (capability_type, capability_id);

COMMENT ON TABLE agent_capability_binding IS 'Agent能力绑定表';
COMMENT ON COLUMN agent_capability_binding.id IS 'ID';
COMMENT ON COLUMN agent_capability_binding.owner_type IS '绑定主体类型';
COMMENT ON COLUMN agent_capability_binding.owner_id IS '绑定主体ID';
COMMENT ON COLUMN agent_capability_binding.capability_type IS '能力类型';
COMMENT ON COLUMN agent_capability_binding.capability_id IS '能力ID';
COMMENT ON COLUMN agent_capability_binding.enabled IS '是否启用';
COMMENT ON COLUMN agent_capability_binding.config_json IS '绑定配置JSON';
COMMENT ON COLUMN agent_capability_binding.version IS '版本';
COMMENT ON COLUMN agent_capability_binding.create_time IS '创建时间';
COMMENT ON COLUMN agent_capability_binding.update_time IS '更新时间';
COMMENT ON COLUMN agent_capability_binding.remark IS '备注';
COMMENT ON COLUMN agent_capability_binding.create_by IS '创建者';
COMMENT ON COLUMN agent_capability_binding.update_by IS '更新者';
