/**
 * Copyright (C) 2026 Ralf Burger
 * ralf@RalfBurger.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

#pragma once
#include <stdint.h>

// -- Array-Groesse -----------------------------------------------
#define MAX_PIDS 48

// -- Benannte Indizes ------------------------------------------
enum PidIdx : uint8_t {
  PID_RPM           =  0,
  PID_SPEED         =  1,
  PID_TEMP          =  2,
  PID_IAT           =  3,
  PID_MAP           =  4,
  PID_LOAD          =  5,
  PID_TPS           =  6,
  PID_CAP00         =  7,
  PID_TANK          =  8,
  PID_VERBRAUCH     =  9,
  PID_MAF           = 10,
  PID_BARO          = 11,
  PID_ABSTPS        = 12,
  PID_RELTPS        = 13,
  PID_GASPEDAL      = 14,
  PID_SCHUBVENTIL   = 15,
  PID_CAP20         = 16,
  PID_CAP40         = 17,
  PID_O2_B1S1_V     = 18,
  PID_O2_B1S2_V     = 19,
  PID_O2_B1S3_V     = 20,
  PID_O2_B1S4_V     = 21,
  PID_O2_B1S1_WB    = 22,
  PID_O2_B1S2_WB    = 23,
  PID_LAMBDA        = 24,
  PID_UMGEBUNGSLUFT = 25,
  PID_KRUEMMERDRUCK = 26,
  PID_ZUENDWINKEL   = 27,
  PID_ECU_SPANNUNG  = 28,
  PID_OELTEMP       = 29,
  PID_EINSPRITZDRUCK= 30,
  PID_KUEHLMITTEL2  = 31,
  PID_CAP60         = 32,
  PID_MIL_STATUS    = 33,
  PID_DIST_MIL      = 34,
  PID_WARMLAUF      = 35,
  PID_DIST_RESET    = 36,
  PID_ZEIT_MIL      = 37,
  PID_ZEIT_RESET    = 38,
  PID_KRAFTSTOFFTYP = 39,
  PID_VIN           = 40,
  PID_KALIBID       = 41,
  PID_ECU_NAME      = 42,
  PID_COUNT_USED    = 43
};

// -- PID-Metadaten-Struct --------------------------------------
struct PidInfo {
  const char* id;
  const char* name;
  const char* unit;
  uint8_t     decimals;
};

// -- Externe Deklarationen (definiert in pid_registry.cpp) -----
// Einmalig im Flash -- kein doppeltes Laden durch mehrere .ino-Dateien
extern const uint8_t PID_SCALE[MAX_PIDS];
extern const PidInfo PID_INFO[MAX_PIDS];
extern const int     PID_INFO_COUNT;

// -- Inline-Hilfsfunktionen ------------------------------------
// inline darf im Header bleiben (Linker fasst Duplikate zusammen)

inline int pidScaleMultiplier(int idx) {
  if (idx < 0 || idx >= MAX_PIDS) return 1;
  switch (PID_SCALE[idx]) {
    case 2: return 100;
    case 1: return 10;
    default: return 1;
  }
}

inline float pidScaleDiv(int idx) {
  if (idx < 0 || idx >= MAX_PIDS) return 1.0f;
  switch (PID_SCALE[idx]) {
    case 2: return 100.0f;
    case 1: return 10.0f;
    default: return 1.0f;
  }
}
