from pathlib import Path

p = Path("/home/shquier/easyconf.net/easychair/app/services/WorkflowDictionary.php")

txt = p.read_text(encoding="utf-8", errors="ignore")

if "public const STATUS_SUBMITTED" in txt:
    print("Pack 2410 already applied: constants exist.")
    raise SystemExit

anchor = "final class WorkflowDictionary\n{"

insert = r'''final class WorkflowDictionary
{
    /*
    ------------------------------------------------------------
    Enterprise Pack 2410
    Canonical workflow constants
    ------------------------------------------------------------
    */

    public const STATUS_SUBMITTED         = 'submitted';
    public const STATUS_SCREENING         = 'screening';
    public const STATUS_UNDER_REVIEW      = 'under_review';
    public const STATUS_REVISION_REQUIRED = 'revision_required';
    public const STATUS_ACCEPTED          = 'accepted';
    public const STATUS_REJECTED          = 'rejected';
    public const STATUS_PRODUCTION        = 'production';
    public const STATUS_ASSIGNED_TO_ISSUE = 'assigned_to_issue';
    public const STATUS_PUBLISHED         = 'published';

    public const STAGE_SUBMISSION = 'submission';
    public const STAGE_SCREENING  = 'screening';
    public const STAGE_REVIEW     = 'review';
    public const STAGE_REVISION   = 'revision';
    public const STAGE_DECISION   = 'decision';
    public const STAGE_PRODUCTION = 'production';
    public const STAGE_ISSUE      = 'issue';
    public const STAGE_PUBLISHED  = 'published';
'''

if anchor not in txt:
    raise SystemExit("ERROR: Could not find class opening anchor.")

txt = txt.replace(anchor, insert, 1)

p.write_text(txt, encoding="utf-8")

print("Pack 2410 applied successfully.")
