/** Odpověď GET /api/v1/sites/{id}/plan/current */

export type PlanningRunDto = {
  id: number
  created_at: string
  run_type: string
  horizon_start: string
  horizon_end: string
  forecast_correction_factor: number | null
  solver_duration_ms: number | null
  /** Snapshot z solve_dispatch (masky, charge_acquisition, …) — volitelné. */
  solver_params?: Record<string, unknown> | null
}

export type PlanningIntervalDto = {
  interval_start: string
  battery_setpoint_w: number | null
  battery_soc_target_pct: number | null
  grid_setpoint_w: number | null
  /** Tvrdý limit exportu do sítě v daném slotu (W); 0 = bez exportu. */
  export_limit_w?: number | null
  /** Záměr exportu: NONE / PV_SURPLUS / BATTERY_SELL. */
  export_mode?: 'NONE' | 'PV_SURPLUS' | 'BATTERY_SELL' | null
  /** Explicitní fyzický režim Deye pro slot (PASSIVE/SELL/CHARGE). */
  deye_physical_mode?: 'PASSIVE' | 'SELL' | 'CHARGE' | null
  /** True = solver plánuje odpojit GEN port (MI export cutoff) v tomto slotu (BA81). */
  deye_gen_cutoff_enabled?: boolean | null
  ev1_setpoint_w: number | null
  ev2_setpoint_w: number | null
  ev_charge_power_w?: number | null
  heat_pump_enabled: boolean | null
  heat_pump_setpoint_w?: number | null
  pv_a_curtailed_w: number | null
  expected_cost_czk: number | null
  effective_buy_price: number | null
  effective_sell_price: number | null
  /** True pokud cena pro slot byla při plánování predikovaná (DB sloupec `is_predicted_price`). */
  is_predicted_price: boolean
  pv_forecast_total_w: number | null
  /** Kanonický PV forecast použitý solverem (A/B). */
  pv_a_forecast_solver_w?: number | null
  pv_b_forecast_solver_w?: number | null
  /** Průměrná skutečná FVE výkon za slot z audit_interval (GET /plan/current JOIN). */
  pv_power_w?: number | null
  load_baseline_w: number | null
}

export type PlanningSummaryDto = {
  total_expected_cost_czk: number
  total_pv_curtailed_kwh: number
  charge_slots: number
  discharge_slots: number
  export_slots: number
  /** 0.65..1.0; nižší znamená očekávaně méně slunce -> větší ochota precharge ze sítě */
  pv_scarcity_factor?: number
}

export type CurrentPlanResponse = {
  run: PlanningRunDto | null
  intervals: PlanningIntervalDto[]
  summary: PlanningSummaryDto | null
}

export type PlanningBundleDto = {
  run: Record<string, unknown>
  intervals: PlanningIntervalDto[]
  summary: Record<string, unknown>
}

export type PlanningSlotDiffDto = {
  interval_start: string
  active: Record<string, unknown>
  comparison: Record<string, unknown>
}

export type PlanningCompareResponse = {
  active: PlanningBundleDto
  comparison: PlanningBundleDto
  diff: Record<string, unknown>
  slot_diffs: PlanningSlotDiffDto[]
}

export type RunPlanResponse = {
  run_id: number
  solver_duration_ms: number
  horizon_start: string
  horizon_end: string
}
