-- Per-venue lat/lon for the city detail dot map.
-- Joins dim_venues to dim_cities to attach country_slug and city_slug
-- (needed by the /api/markets/<country>/<city>/venues.json endpoint).
-- Only rows with valid coordinates are included.

MODEL (
  name serving.city_venue_locations,
  kind FULL,
  cron '@daily',
  grain venue_id
);

SELECT
  v.venue_id,
  v.name,
  v.lat,
  v.lon,
  v.court_count,
  v.indoor_court_count,
  v.outdoor_court_count,
  v.city_slug,
  c.country_slug
FROM foundation.dim_venues v
JOIN foundation.dim_cities c
  ON v.country_code = c.country_code AND v.city_slug = c.city_slug
WHERE v.lat IS NOT NULL AND v.lon IS NOT NULL
