# -*- coding: utf-8 -*-
"""Offbox-rename gate (v0.123.0) — the Tier-3 feature is branded "Távoli mentés" everywhere
customer-facing: the productized target is the Storage Box and the tier concept is "offsite",
so "NAS-mentés"-style branding must not reappear in the offbox feature's customer strings.
Python, not grep: Hungarian multibyte (the Windows-grep false-negative rule).

Scope: ONLY the offbox feature's files. The "Hálózati tárhely" NAS network-storage feature is a
DIFFERENT feature and keeps its device-truthful NAS wording (its files are not scanned). Allowed
by construction (no banned token): the intro's "saját NAS vagy Felhom offsite tárhely" and the
manual-target form's "NAS vagy SFTP-kiszolgáló" mentions, comments, code identifiers/routes.

Run from controller/:  python scripts/offbox_rename_gate.py
"""
import io, os, sys

FILES = [
    os.path.join("internal", "web", "templates", "backups.html"),
    os.path.join("internal", "web", "offbox_handlers.go"),
    os.path.join("internal", "backup", "offbox.go"),
]

BANNED = [
    "NAS-mentés",
    "NAS mentési",
    "NAS-visszaállítás",
    "a NAS-ra",
    "a NAS-ról",
    "NAS címe",
    "a NAS-on",
    "NAS ismert-host",
]


def is_comment(line):
    s = line.strip()
    return s.startswith("//") or s.startswith("<!--") or s.startswith("/*") or s.startswith("*")


def main():
    total = 0
    for path in FILES:
        for lineno, line in enumerate(io.open(path, encoding="utf-8"), 1):
            if is_comment(line):
                continue
            for tok in BANNED:
                if tok in line:
                    total += 1
                    print("%s:%d  [%s]  %s" % (path, lineno, tok,
                          line.strip()[:100].encode("ascii", "backslashreplace").decode()))
    if total:
        print("OFFBOX RENAME GATE FAILED: %d customer-facing NAS-branding string(s) remain" % total)
        sys.exit(1)
    print("offbox rename gate OK — Tier-3 is 'Tavoli mentes' everywhere customer-facing")


if __name__ == "__main__":
    main()
