-- V002: ai_agents
-- AI 에이전트 테이블

CREATE TABLE ai_agents (
    id              BIGSERIAL PRIMARY KEY,
    agent_id        VARCHAR(64) NOT NULL UNIQUE,
    name            VARCHAR(200) NOT NULL,
    description     TEXT,
    model           VARCHAR(100) NOT NULL DEFAULT 'claude-sonnet-4-20250514',
    system_prompt   TEXT,
    tools           JSONB NOT NULL DEFAULT '[]'::jsonb,
    config          JSONB NOT NULL DEFAULT '{}'::jsonb,
    status          VARCHAR(20) NOT NULL DEFAULT 'active'
                    CHECK (status IN ('active','inactive','archived')),
    company_code    VARCHAR(20),
    created_by      VARCHAR(64) NOT NULL,
    created_at      TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at      TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_ai_agents_company ON ai_agents (company_code);
CREATE INDEX idx_ai_agents_status  ON ai_agents (status);
CREATE INDEX idx_ai_agents_created ON ai_agents (created_at DESC);
