====================================================================
WORKFLOW_SEED_NVME_SYNOLOGY.txt
Projet : Seedbox Manager
Objet  : Flux Hot→Warm (NVMe→Synology) – mapping, états, timers
Version : 1.0 (2025-10-12)
====================================================================

1) OBJECTIF & PÉRIMÈTRE
-----------------------
Garantir un seed initial sur NVMe, puis une bascule fiable vers Synology
selon des règles (âge, catégorie, espace), en s’appuyant sur .state,
mapping et scripts “daily”.

2) ACTEURS & RÉPERTOIRES
------------------------
- Post-process ARR   : /scripts/state/ (écrit *.state)
- Daily qBittorrent  : /scripts/daily_qbittorrent_update.sh
- Mapping            : /scripts/mapping_entries.txt (ou SQLite si retenu)
- Journaux           : /scripts/log/
- Verrous (locks)    : /scripts/locks/

3) SÉQUENCE (VUE D’ENSEMBLE)
----------------------------
[ARR Import] → écrit .state(kind/added/upgrade/old/new)
      ↓
[Daily] lit .state éligibles (âge, catégorie, espace) 
      ↓
API qBittorrent (setLocation, recheck) → bascule vers Synology
      ↓
[Mapping] mise à jour (entrée hash ↔ chemins)
      ↓
[Nettoyage] purge des .state traités + rotation journaux

4) RÈGLES D’ÉLIGIBILITÉ (EXEMPLES À ADAPTER)
--------------------------------------------
- Âge minimal (min_age_sec) : … (ex. 7 jours)
- Catégories éligibles      : tv, movies, …
- Espace libre cible        : seuil % / Go
- Connexion Synology        : test de montage avant action

5) FICHIERS & CONTRATS
----------------------
- .state  : cf. STATE_SCHEMA.txt
- mapping : TSV ou CSV ; colonnes minimales :
            infohash, path_nvme, path_syno, last_update_epoch
- logs    : un fichier par script (rotation 7-15 jours)

6) ÉCHECS & REPRISE
-------------------
- Si Synology indisponible : log WARN, ne pas déplacer, reprogrammer.
- Si API qB échec         : retry (x3) puis abandon contrôlé.
- Toujours laisser le seed intact en cas d’erreur.

7) TESTS (CHECKLIST)
--------------------
- C-01 : .state valide → bascule OK.
- C-02 : min_age non atteint → aucun mouvement.
- C-03 : Synology off → pas d’action, log WARN.
- C-04 : mapping mis à jour, cohérence des chemins.
- C-05 : rotation des logs opérationnelle.

8) KPIs & OBSERVABILITÉ
-----------------------
- % réussites / tentatives
- Temps moyen de bascule
- Volume journalier déplacé
- Erreurs par cause (réseau, API, droits)

9) VERSIONNEMENT
----------------
- WORKFLOW_VERSION=1
- Toute évolution majeure documentée ici.

====================================================================
FIN – WORKFLOW_SEED_NVME_SYNOLOGY.txt
====================================================================
