-- select * from main.vms limit 10;
--
--
-- main vms
--     elenco pannelli
--
-- main displays
--     vms_id = main.vms.id
--     datetime ts inizio evento
--     components array di riferimenti a main.components
--
--
-- main.components
--     page_id pagina a cui viene visualizzato il componenete nel pannello

select
     pmv.id
    ,pmv.description
    ,pmv.road_number
    ,pmv.road_lcd
    ,pmv.direction_id
--     ,ST_AsGeoJson(pmv.geometry) as geometry
    ,ST_X(pmv.geometry) as point_x
    ,ST_Y(pmv.geometry) as point_y
    ,pmv.start_meters
    ,pmv.end_meters
    ,pmv.vms_type_id as panel_type
    ,dis.datetime
    ,dis.components
    -- descrizione del tipo di pannello (probabilmente inutile)
--     ,vt.description
    -- descrizione dei componenti del pannello (probabilmente inutile)
--     ,vt.components
from
    main.vms as pmv
    left join main.displays as dis on
        pmv.is_current = true
        and dis.is_current = true
        and pmv.id = dis.vms_id
--    left join main.components as com on
--         com.id in dis.components
--     left join data.vms_types as vt on
--             pmv.vms_type_id = vt.id
-- limit 100
where pmv.is_current = true;
