from pathlib import Path

files = list(Path("app/services").glob("staff.py")) + list(Path("app/services").glob("booking.py")) + list(Path("app/services").glob("attendance.py")) + list(Path("app/services").glob("training.py"))

for p in files:
    text = p.read_text(encoding="utf-8")
    text = text.replace("actor.subject", "actor.user_id if actor else None")
    text = text.replace(
        "from app.validators import validate_code, validate_file_ref, validate_non_empty",
        "from app.validators import validate_code, validate_non_empty\nfrom app.validators.members import validate_file_ref",
    )
    while "await self.audit.log(" in text:
        start = text.index("await self.audit.log(")
        end = text.index(")", start) + 1
        text = text[:start] + text[end + 1 :]
    p.write_text(text, encoding="utf-8")
    print("fixed", p)
