from pathlib import Path

p = Path("/home/shquier/easyconf.net/easychair/app/services/WorkflowDecisionService.php")
txt = p.read_text(encoding="utf-8", errors="ignore")

if "use App\\Services\\WorkflowDictionary;" not in txt:
    txt = txt.replace(
        "use App\\Services\\StageTransitionService;\n",
        "use App\\Services\\StageTransitionService;\nuse App\\Services\\WorkflowDictionary;\n",
        1
    )

replacements = {
    "$targetStage = 'review';": "$targetStage = WorkflowDictionary::STAGE_REVIEW;",
    "$status      = 'under_review';": "$status      = WorkflowDictionary::STATUS_UNDER_REVIEW;",
    "$targetStage = 'production';": "$targetStage = WorkflowDictionary::STAGE_PRODUCTION;",
    "$status      = 'accepted';": "$status      = WorkflowDictionary::STATUS_ACCEPTED;",
    "$targetStage = 'revision';": "$targetStage = WorkflowDictionary::STAGE_REVISION;",
    "$status      = 'revision_required';": "$status      = WorkflowDictionary::STATUS_REVISION_REQUIRED;",
    "$targetStage = 'decision';": "$targetStage = WorkflowDictionary::STAGE_DECISION;",
    "$status      = 'rejected';": "$status      = WorkflowDictionary::STATUS_REJECTED;",
}

for old, new in replacements.items():
    txt = txt.replace(old, new)

p.write_text(txt, encoding="utf-8")
print("Pack 2413 applied.")
