-- Vzorek telemetrie EV nabíječky (1min, Timescale). Od 2026-06-11 vč. proudu
-- (Teltonika reg 3–5, max fáze) — starou 7-arg signaturu dropnout (jinak by
-- volání s defaultem bylo ambiguózní).

drop function if exists ems.fn_telemetry_ev_charger_sample(
  int, int, timestamptz, int, text, int, double precision
);

create or replace function ems.fn_telemetry_ev_charger_sample(
  p_site_id int,
  p_charger_id int,
  p_measured_at timestamptz,
  p_connector_id int,
  p_status text,
  p_power_w int,
  p_energy_kwh double precision,
  p_current_a double precision default null
)
returns void
language sql
as $fn$
  insert into ems.telemetry_ev_charger (
    site_id,
    charger_id,
    measured_at,
    connector_id,
    status,
    power_w,
    energy_kwh,
    current_a
  )
  values (
    p_site_id,
    p_charger_id,
    p_measured_at,
    p_connector_id,
    p_status,
    p_power_w,
    p_energy_kwh,
    p_current_a
  )
  on conflict (charger_id, connector_id, measured_at) do nothing;
$fn$;

comment on function ems.fn_telemetry_ev_charger_sample is
'Vloží 1min vzorek telemetrie EV nabíječky (status, výkon, energie session, proud). Idempotentní na (charger, connector, čas).';
