#ifndef CONFIG_LEDS_H
#define CONFIG_LEDS_H

#include <Arduino.h>

// Configuration de la nouvelle structure 4R-3333L
// 4 Faces, 3 Lignes par face, 59 LEDs par ligne
#define NUM_FACES 4
#define NUM_LINES_PER_FACE 3
#define LEDS_PER_LINE 59

// Structure pour définir un segment de ruban
struct LedSegment {
    int rubanIdx; // 0 à 3
    int startIdx; // Index physique de début
    int endIdx;   // Index physique de fin
};

// Mapping précis basé sur tes données
// Chaque face possède 3 segments (lignes)
const LedSegment mapping[NUM_FACES][NUM_LINES_PER_FACE] = {
    // Face 0 (Ruban 1)
    {
        {0, 0, 58},    // Ligne 1
        {0, 60, 118},  // Ligne 2
        {0, 119, 177}  // Ligne 3
    },
    // Face 1 (Ruban 2)
    {
        {1, 1, 59},    // Ligne 1
        {1, 61, 119},  // Ligne 2
        {1, 120, 178}  // Ligne 3
    },
    // Face 2 (Ruban 3)
    {
        {2, 0, 58},    // Ligne 1
        {2, 59, 117},  // Ligne 2
        {2, 118, 176}  // Ligne 3
    },
    // Face 3 (Ruban 4)
    {
        {3, 1, 59},    // Ligne 1
        {3, 60, 118},  // Ligne 2
        {3, 120, 178}  // Ligne 3
    }
};

/**
 * Fonction de mapping pour traduire une coordonnée virtuelle en index physique.
 * @param face (0-3)
 * @param ligne (0-2)
 * @param index_ligne (0-58)
 * @return L'index physique de la LED, ou -1 si hors limites.
 */
inline int getPhysicalIndex(int face, int ligne, int index_ligne) {
    if (face < 0 || face >= NUM_FACES || 
        ligne < 0 || ligne >= NUM_LINES_PER_FACE || 
        index_ligne < 0 || index_ligne >= LEDS_PER_LINE) {
        return -1;
    }
    
    LedSegment seg = mapping[face][ligne];
    return seg.startIdx + index_ligne;
}

/**
 * Retourne l'index du ruban pour une coordonnée virtuelle.
 */
inline int getPhysicalRuban(int face, int ligne) {
    return mapping[face][ligne].rubanIdx;
}

#endif // CONFIG_LEDS_H