/** ems.vw_site_status (PostgREST) */
export type SiteStatusRow = {
  site_id: number
  site_code: string
  site_name: string
  active_mode: string | null
  mode_name: string | null
  mode_description: string | null
  is_autonomous: boolean | null
  activated_at: string | null
  activated_by: string | null
  valid_until: string | null
  previous_mode: string | null
  mode_notes: string | null
  ems_last_seen: string | null
  ems_status: string | null
  ems_age_seconds: number | null
  ems_heartbeat_status: 'ok' | 'delayed' | 'stale' | 'never_seen' | null
  pv_power_w: number | null
  battery_soc_percent: string | number | null
  battery_power_w: number | null
  grid_power_w: number | null
  load_power_w: number | null
  telemetry_at: string | null
}

/** ems.vw_audit_today_hourly */
export type AuditTodayHourlyRow = {
  site_id: number
  hour_local: string
  avg_pv_kw: string | number | null
  avg_battery_kw: string | number | null
  avg_grid_kw: string | number | null
  avg_load_kw: string | number | null
  avg_soc_pct: string | number | null
  cost_czk: string | number | null
}

/** ems.vw_telemetry_hourly_7d (řádky z telemetry_inverter_hourly) */
export type TelemetryHourly7dRow = {
  hour: string
  site_id: number
  avg_pv_w: number | null
  avg_battery_w: number | null
  avg_grid_w: number | null
  avg_load_w: number | null
  last_soc_pct: string | number | null
  sample_count: number | null
}

/** ems.vw_telemetry_15m_7d (řádky z telemetry_inverter_15m) */
export type Telemetry15m7dRow = {
  slot_start: string
  site_id: number
  avg_pv_w: number | null
  avg_battery_w: number | null
  avg_grid_w: number | null
  avg_load_w: number | null
  last_soc_pct: string | number | null
  sample_count: number | null
}

/** ems.vw_latest_heat_pump */
export type HeatPumpLatestRow = {
  site_id: number
  heat_pump_id: number
  heat_pump_code: string | null
  measured_at: string
  tuv_tank_temp_c: number | string | null
  power_w: number | null
}

/** ems.vw_audit_daily */
export type AuditDailyRow = {
  site_id: number
  day_local: string
  interval_count: number
  import_kwh: string | number | null
  export_kwh: string | number | null
  pv_kwh: string | number | null
  load_kwh: string | number | null
  ev_kwh: string | number | null
  hp_kwh: string | number | null
  actual_cost_czk: string | number | null
  total_deviation_czk: string | number | null
  high_deviation_count: number | null
}

/** ems.vw_mode_log_recent (PostgREST) */
export type ModeLogRecentRow = {
  id: number
  site_id: number
  site_code: string
  mode_code: string
  mode_name: string
  activated_at: string
  deactivated_at: string | null
  duration_sec: number
  activated_by: string | null
  notes: string | null
}

/** ems.vw_site_effective_price */
export type SiteEffectivePriceRow = {
  site_id: number
  interval_start: string
  interval_end: string
  effective_buy_price_czk_kwh: string | number | null
  effective_sell_price_czk_kwh: string | number | null
}
