DROP VIEW IF EXISTS mv_reports_ucepsa_demo.latest_machine_state_fast;

CREATE VIEW mv_reports_ucepsa_demo.latest_machine_state_fast AS
SELECT
    ts,
    ingest_ts,
    age_s,
    tenant,
    site,
    asset,
    machine_id,
    order_id,
    voltage_l1_v,
    current_l1_a,
    power_total_kw,
    frequency_hz,
    import_kwh,
    export_kwh,
    comm_ok,
    error_text,
    machine_auto_signal,
    machine_running,
    cycle_pulse_count,
    cycle_rate_ppm,
    last_cycle_age_s,
    digital_inputs,
    payload_json
FROM mv_reports_ucepsa_demo.latest_machine_snapshot;

GRANT SELECT ON mv_reports_ucepsa_demo.latest_machine_state_fast TO grafana_ucepsa_ro;
