# -*- coding: utf-8 -*-
import glob
import re
import sys

sys.stdout.reconfigure(encoding="utf-8")

def audit_en():
    print("=== AUDITING EN POV SLIPS ===")
    for fpath in sorted(glob.glob("novels/locales/en/act_*/*.md")):
        lines = open(fpath, encoding="utf-8").readlines()
        for idx, line in enumerate(lines):
            s = line.strip()
            if not s or s.startswith(("#", ">", "---", "—", "-", '"', "“", "「")):
                continue
            matches = re.findall(r"\b(I|my|me|mine|myself)\b", s)
            if matches:
                print(f"{fpath}:{idx+1} {matches}: {s}")

def audit_es():
    print("=== AUDITING ES POV SLIPS ===")
    for fpath in sorted(glob.glob("novels/locales/es/act_*/*.md")):
        lines = open(fpath, encoding="utf-8").readlines()
        for idx, line in enumerate(lines):
            s = line.strip()
            if not s or s.startswith(("#", ">", "---", "—", "-", '"', "“", "「")):
                continue
            matches = re.findall(r"\b(mi|mis|conmigo|yo)\b", s, re.IGNORECASE)
            if matches:
                print(f"{fpath}:{idx+1} {matches}: {s}")

def audit_de():
    print("=== AUDITING DE POV SLIPS ===")
    for fpath in sorted(glob.glob("novels/locales/de/act_*/*.md")):
        lines = open(fpath, encoding="utf-8").readlines()
        for idx, line in enumerate(lines):
            s = line.strip()
            if not s or s.startswith(("#", ">", "---", "—", "-", '"', "“", "「")):
                continue
            matches = re.findall(r"\b(ich|mein|meine|meinem|meinen|meiner|meines|mir|mich)\b", s, re.IGNORECASE)
            if matches:
                print(f"{fpath}:{idx+1} {matches}: {s}")

def audit_ru():
    print("=== AUDITING RU POV SLIPS ===")
    for fpath in sorted(glob.glob("novels/locales/ru/act_*/*.md")):
        lines = open(fpath, encoding="utf-8").readlines()
        for idx, line in enumerate(lines):
            s = line.strip()
            if not s or s.startswith(("#", ">", "---", "—", "-", '"', "“", "「")):
                continue
            matches = re.findall(r"\b(я|мой|моя|мое|моё|мои|моего|моей|моих|моему|моим|меня|мне|мной|мною)\b", s, re.IGNORECASE)
            if matches:
                print(f"{fpath}:{idx+1} {matches}: {s}")

def audit_zh():
    print("=== AUDITING ZH POV SLIPS ===")
    for fpath in sorted(glob.glob("novels/locales/zh/act_*/*.md")):
        lines = open(fpath, encoding="utf-8").readlines()
        for idx, line in enumerate(lines):
            s = line.strip()
            if not s or s.startswith(("#", ">", "---", "—", "-", '"', "“", "「")):
                continue
            matches = re.findall(r"我|我的", s)
            if matches:
                # filter out obvious things if any
                print(f"{fpath}:{idx+1} {matches}: {s}")

def audit_de_act123():
    print("=== AUDITING DE ACT 1-3 POV SLIPS ===")
    for fpath in sorted(glob.glob("novels/locales/de/act_[123]/*.md")):
        lines = open(fpath, encoding="utf-8").readlines()
        for idx, line in enumerate(lines):
            s = line.strip()
            if not s or s.startswith(("#", ">", "---", "—", "-", "–", '"', "“", "「")):
                continue
            matches = re.findall(r"\b(ich|mein|meine|meinem|meinen|meiner|meines|mir|mich)\b", s, re.IGNORECASE)
            if matches:
                print(f"{fpath}:{idx+1} {matches}: {s}")

def audit_ja():
    print("=== AUDITING JA POV SLIPS ===")
    for fpath in sorted(glob.glob("novels/locales/ja/act_*/*.md")):
        lines = open(fpath, encoding="utf-8").readlines()
        for idx, line in enumerate(lines):
            s = line.strip()
            if not s or s.startswith(("#", ">", "---", "—", "-", "–", '"', "“", "「")):
                continue
            matches = re.findall(r"私|私の|俺|俺の|僕|僕の", s)
            if matches:
                print(f"{fpath}:{idx+1} {matches}: {s}")

def audit_ko():
    print("=== AUDITING KO POV SLIPS ===")
    for fpath in sorted(glob.glob("novels/locales/ko/act_*/*.md")):
        lines = open(fpath, encoding="utf-8").readlines()
        for idx, line in enumerate(lines):
            s = line.strip()
            if not s or s.startswith(("#", ">", "---", "—", "-", "–", '"', "“", "「")):
                continue
            matches = re.findall(r"\b(나의|내가|나를|내|나|저의|제가|저를|저)\b", s)
            if matches:
                print(f"{fpath}:{idx+1} {matches}: {s}")

if __name__ == "__main__":
    audit_en()
    audit_es()
    audit_de_act123()
    audit_ru()
    audit_zh()
    audit_ja()
    audit_ko()


