-- V009: ai_agent_schedules
-- AI 에이전트 스케줄 테이블 (Quartz JDBC 연동)

CREATE TABLE ai_agent_schedules (
    id               BIGSERIAL PRIMARY KEY,
    name             VARCHAR(200) NOT NULL,
    group_id         BIGINT NOT NULL REFERENCES ai_agent_groups(id) ON DELETE CASCADE,
    cron_expression  VARCHAR(100) NOT NULL,
    timezone         VARCHAR(50) NOT NULL DEFAULT 'Asia/Seoul',
    input_message    TEXT NOT NULL,
    notification     JSONB NOT NULL DEFAULT '{}'::jsonb,
    is_active        BOOLEAN NOT NULL DEFAULT TRUE,
    last_run_at      TIMESTAMPTZ,
    run_count        BIGINT NOT NULL DEFAULT 0,
    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_sched_active  ON ai_agent_schedules (is_active);
CREATE INDEX idx_sched_company ON ai_agent_schedules (company_code);
