#!/usr/bin/env python3
from pathlib import Path
import sys, json
VERSION='0.2.5b'
THEMES=[('aegis-gold','AEGIS Gold','SentinelOS-Dark-Gold',True),('sentinel-dark','SentinelOS Dark','SentinelOS-Dark-Cyan',False),('sentinel-light','SentinelOS Light','SentinelOS-Light-Cyan',False)]
REQ=['preview.png','thumbnail.png','gtk-2.0/thumbnail.png','metacity-1/thumbnail.png','index.theme']
def summary():
    print('SentinelOS Theme Preview Polish')
    print('version:', VERSION)
    print('purpose: Appearance Preferences preview thumbnail cleanup')
    print('goal: replace question-mark placeholders with professional theme previews')
    print('live_apply_on_install: no')
    print('wallpaper_changes: no')
    for key,display,theme,opt in THEMES:
        root=Path('/usr/share/themes')/theme
        print(f'{key}: display={display} theme={theme} state={"present" if root.exists() else ("optional-missing" if opt else "missing")}')
def verify():
    ok=True
    for key,display,theme,opt in THEMES:
        root=Path('/usr/share/themes')/theme
        if not root.exists():
            if opt:
                print(f'{key}: optional theme not installed')
                continue
            print(f'{key}: missing theme {theme}'); ok=False; continue
        for r in REQ:
            p=root/r
            if not p.exists():
                print(f'{key}: missing {r}'); ok=False
            elif p.stat().st_size < 200:
                print(f'{key}: suspicious-small {r}'); ok=False
        idx=(root/'index.theme').read_text(errors='ignore') if (root/'index.theme').exists() else ''
        if f'Name={display}' not in idx:
            print(f'{key}: display name mismatch in index.theme'); ok=False
        print(f'{key}: preview_assets={"ok" if ok else "checked"}')
    print('verify: ok' if ok else 'verify: failed')
    return 0 if ok else 1
args=sys.argv[1:]
if not args or '--summary' in args: summary(); sys.exit(0)
if '--verify' in args or '--preflight' in args: sys.exit(verify())
print('usage: sentinelos-theme-preview-polish --summary|--preflight|--verify')
sys.exit(2)
