-- 170_scrape_schedules_seed_osm_poi_ekb_refresh.sql
-- Scheduler seed for the OSM POI local-mirror refresh job (#2045 BE-3, LocationDrawer).
--
-- WHAT (source='osm_poi_ekb_refresh'):
--   trigger_osm_poi_ekb_refresh_run (scheduler.py) → run_osm_poi_ekb_refresh
--   (tasks/osm_poi_ekb_refresh.py). Single bulk FDW scan: TRUNCATE osm_poi_ekb_local;
--   INSERT ... SELECT FROM gendesign_osm_poi_ekb, building a Point(4326) geom from lat/lon.
--
--   OSM POI data changes rarely (Site Finder refreshes its own osm_poi_ekb table
--   infrequently) — a daily cadence is more than sufficient freshness margin at near-zero
--   cost (pure internal DB op, no external HTTP/anti-bot).
--
-- SAFE to enable by default (enabled=true), like cadastral_geo_match (seed 125).
--
-- Window 10:00-11:00 UTC (13:00-14:00 MSK): after cadastral_geo_match (09:00-10:00 UTC);
--   pure-DB so no contention with scraper/proxy work either way.
--
-- next_run_at = tomorrow 10:00 UTC (NOT NULL — avoid deploy-time fire, same convention as
--   the cadastral_geo_match seed 125; NULL would make get_due_schedules pick it up on the
--   very next tick).
--
-- DEPENDENCIES: 052_scrape_schedules.sql (table + UNIQUE(source)), 169_osm_poi_ekb_local.sql.
-- Idempotent: ON CONFLICT (source) DO NOTHING.

BEGIN;

INSERT INTO scrape_schedules (
    source,
    enabled,
    window_start_hour,
    window_end_hour,
    next_run_at,
    default_params
)
VALUES
(
    'osm_poi_ekb_refresh',
    true,
    10,
    11,
    ((CURRENT_DATE + INTERVAL '1 day') + make_interval(hours => 10)) AT TIME ZONE 'UTC',
    '{}'::jsonb
)
ON CONFLICT (source) DO NOTHING;

COMMIT;
