# FILE: _St/RTC8790_8791/test_rtc8790_tray_startup_v310.py | ROLE: RTC 시작 Tray 숨김·공용 EXT 아이콘 회귀
from __future__ import annotations

from pathlib import Path


def test_rtc_tray_startup_contract() -> None:
    root = Path(__file__).resolve().parent
    st_root = root.parent
    source = (root / "yjm_win2rtc_capture.py").read_text(encoding="utf-8")
    entry = (root / "rtc8790_8791_main.py").read_text(encoding="utf-8")
    tray = (st_root / "Shared" / "windows_tray.py").read_text(encoding="utf-8")
    icon = st_root / "Shared" / "assets" / "ig_styellow_tray.ico"
    ext_icon = st_root / "IG_StYellow" / "icons" / "logo.png"

    assert icon.is_file() and icon.stat().st_size > 0
    assert ext_icon.is_file() and ext_icon.stat().st_size > 0
    assert 'TRAY_ICON_PATH = ST_ROOT / "Shared" / "assets" / "ig_styellow_tray.ico"' in source
    assert 'WindowsTrayIcon("RTC8790_8791", "RTC8790_8791 - 클릭하여 화면 복원", icon_path=TRAY_ICON_PATH)' in source
    assert 'self.root.after(80, self.hide_to_tray_on_startup)' in source
    assert 'def hide_to_tray_on_startup(self):' in source
    assert 'self.root.withdraw()' in source
    assert 'def restore_from_tray(self):' in source
    assert 'ttk.Button(btns, text=".", width=3, command=self.hide_to_tray)' in source
    assert 'if self.tray is not None:\n                self.tray.stop()' in source
    assert 'root = tk.Tk()\n    root.withdraw()\n    Win2RtcApp(root, args)' in source
    assert 'from yjm_win2rtc_capture import main' in entry
    assert 'icon_path: str | os.PathLike[str] | None = None' in tray
    assert 'LoadImageW(None, self.icon_path, IMAGE_ICON' in tray


def test_auto_ws_use_same_project_tray_icon() -> None:
    st_root = Path(__file__).resolve().parent.parent
    auto = (st_root / "Auto8700" / "auto_service8700_manager.py").read_text(encoding="utf-8")
    ws = (st_root / "WS8771" / "ws8771_main.py").read_text(encoding="utf-8")
    marker = 'TRAY_ICON_PATH = ST_ROOT / "Shared" / "assets" / "ig_styellow_tray.ico"'
    assert marker in auto
    assert marker in ws
    assert 'icon_path=TRAY_ICON_PATH' in auto
    assert 'icon_path=TRAY_ICON_PATH' in ws
