-- Add Scheduled Job for Fetching Close Approach Events
-- This uses the predefined task: fetch_close_approach_events
--
-- 参数说明:
-- - days_ahead: 30 (查询未来30天的事件)
-- - dist_max: "30" (30 AU，海王星轨道范围)
-- - approach_body: "Earth" (接近地球的天体)
-- - limit: 200 (最多返回200个事件)
-- - clean_old_events: true (清理过期事件)
--
-- Cron表达式: '0 2 * * 0' (每周日UTC 02:00执行)
--
-- 注意: 任务会自动创建不存在的天体记录（小行星/彗星）

INSERT INTO "public"."scheduled_jobs"
("name", "job_type", "predefined_function", "function_params", "cron_expression", "description", "is_active")
VALUES
(
    '每周天体事件拉取 (Close Approaches)',
    'predefined',
    'fetch_close_approach_events',
    '{
        "days_ahead": 30,
        "dist_max": "30",
        "approach_body": "Earth",
        "limit": 200,
        "clean_old_events": true
    }'::jsonb,
    '0 2 * * 0',
    '每周日UTC 02:00从NASA SBDB拉取未来30天内距离地球30AU以内（海王星轨道范围）的小行星/彗星接近事件',
    true
)
ON CONFLICT DO NOTHING;