from pathlib import Path

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

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

replacements = {
    "status = 'under_review',": "status = '" + "' . WorkflowDictionary::STATUS_UNDER_REVIEW . '" + "',",
}

# Safer direct text replacements for SQL strings
txt = txt.replace("status = 'revised',", "status = 'revised',")
txt = txt.replace("stage = 'review',", "stage = '" + "' . WorkflowDictionary::STAGE_REVIEW . '" + "',")
txt = txt.replace("status = 'under_review',", "status = '" + "' . WorkflowDictionary::STATUS_UNDER_REVIEW . '" + "',")
txt = txt.replace("stage = 'decision',", "stage = '" + "' . WorkflowDictionary::STAGE_DECISION . '" + "',")
txt = txt.replace("workflow_stage = 'decision',", "workflow_stage = '" + "' . WorkflowDictionary::STAGE_DECISION . '" + "',")
txt = txt.replace("status = 'production',", "status = '" + "' . WorkflowDictionary::STATUS_PRODUCTION . '" + "',")
txt = txt.replace("stage = 'production',", "stage = '" + "' . WorkflowDictionary::STAGE_PRODUCTION . '" + "',")

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