from utils.gitea import recuperer_date_dernier_commit
#
# from config import GITEA_URL, GITEA_TOKEN, ORGANISATION, DEPOT_FICHES, DEPOT_CODE, ENV, ENV_CODE, DOT_FILE
#
#def recuperer_date_dernier_commit(url):
#    headers = {"Authorization": f"token {GITEA_TOKEN}"}
#    try:
#        response = requests.get(url, headers=headers, timeout=10)
#        response.raise_for_status()
#        commits = response.json()
#        if commits:
#            return parser.isoparse(commits[0]["commit"]["author"]["date"])
#    except Exception as e:
#        logging.error(f"Erreur récupération commit schema : {e}")
#    return None
#
# path_relative = f"Documents/{dossier_choisi}/{fiche_choisie}"
# commits_url = f"{GITEA_URL}/repos/{ORGANISATION}/{DEPOT_FICHES}/commits?path={path_relative}&sha={ENV}"
#
# local_mtime = datetime.fromtimestamp(os.path.getmtime(path_relative), tz=timezone.utc)
# remote_mtime = recuperer_date_dernier_commit(commit_url)

MAKE = {
    "assets": {
        "directory": "assets",
        "seuils": {
            "depends_on": "None",
        },
        "file": {
            "seuils": "config.yaml"
        }
    },
    "fiches": {
        "directory": "Fiches",
        "criticites": {
            "directory": "Criticités",
            "préfix": "Fiche technique ",
            "depends_on": {
                "gitea": {
                    "compare": "file2commit"
                },
                "document": {
                    "seuils": {
                        "where": "assets.file.seuils",
                        "compare": "file2file"
                    }
                }
            },
            "file": {
                "ihh": "Fiche technique IHH.md",
                "isg": "Fiche technique ISG.md",
                "ivc": "Fiche technique IVC.md",
                "ics": "Fiche technique ICS.md"
            }
        },
        "assemblage": {
            "directory": "Assemblage",
            "prefix": "Fiche assemblage ",
            "depends_on": {
                "gitea": {
                    "compare": "file2commit"
                },
                "document": {
                    "ihh": {
                        "where": "fiches.criticites.file.ihh",
                        "compare": "file2file"
                    },
                    "isg": {
                        "where": "fiches.criticites.file.isg",
                        "compare": "file2file"
                    }
                }
            }
        },
        "fabrication": {
            "directory": "Fabrication",
            "prefix": "Fiche fabrication ",
            "depends_on": {
                "gitea": {
                    "compare": "file2commit"
                },
                "document": {
                    "ihh": {
                        "where": "fiches.criticites.file.ihh",
                        "compare": "file2file"
                    },
                    "isg": {
                        "where": "fiches.criticites.file.isg",
                        "compare": "file2file"
                    }
                }
            }
        },
        "connexe": {
            "directory": "Connexe",
            "prefix": "Fiche assemblage ",
            "depends_on": {
                "gitea": {
                    "compare": "file2commit"
                },
                "document": {
                    "ihh": {
                        "where": "fiches.criticites.file.ihh",
                        "compare": "file2file"
                    },
                    "isg": {
                        "where": "fiches.criticites.file.isg",
                        "compare": "file2file"
                    }
                }
            }
        },
        "minerai": {
            "directory": "Minerai",
            "prefix": "Fiche minerai ",
            "depends_on": {
                "gitea": {
                    "compare": "file2commit"
                },
                "document": {
                    "ihh": {
                        "where": "fiches.criticites.file.ihh",
                        "compare": "file2file"
                    },
                    "isg": {
                        "where": "fiches.criticites.file.isg",
                        "compare": "file2file"
                    },
                    "ics": {
                        "where": "fiches.criticites.file.ics",
                        "compare": "file2file"
                    },
                    "ivc": {
                        "where": "fiches.criticites.file.ivc",
                        "compare": "file2file"
                    }
                }
            }
        }
    }
}
