from pathlib import Path
import sys
ROOT=Path(__file__).resolve().parents[1]
settings=(ROOT/'src/com/lemenzo/messenger/SettingsActivity.java').read_text()
retention=(ROOT/'src/com/lemenzo/messenger/retention/MessageRetentionManager.java').read_text()
strings=(ROOT/'res/values/strings.xml').read_text()
colors=(ROOT/'res/values/colors.xml').read_text().lower()
errors=[]
for v in ['"off"','"24h"','"2d"','"4d"','"7d"','"14d"']:
    if v not in settings: errors.append(f'Missing Settings retention value {v}')
for label in ['retention_off','retention_24_hours','retention_2_days','retention_4_days','retention_7_days','retention_14_days']:
    if f'R.string.{label}' not in settings: errors.append(f'Missing visible retention choice {label}')
if 'MessageRetentionManager.apply(this, value)' not in settings:
    errors.append('Retention selection is not applied')
if 'message_retention_dialog_explanation' not in settings or 'Automatic Message Cleanup' not in strings or 'historical communication data' not in strings:
    errors.append('Retention explanation/privacy framing is incomplete')
if 'choiceRow(labels[i], selected)' not in settings or 'selected ? "✓" : ""' not in settings:
    errors.append('Retention dialog lacks visible selectable/current state UI')
if 'android.app.AlertDialog' in settings:
    errors.append('Settings still uses default AlertDialog styling')
for required in ['lemenzo_settings_background','lemenzo_settings_surface','lemenzo_settings_blue','lemenzo_settings_text_secondary','lemenzo_settings_divider']:
    if f'R.color.{required}' not in settings and required not in colors:
        errors.append(f'Missing Lemenzo Settings palette resource {required}')
if 'content://mms-sms/conversations/obsolete' not in retention:
    errors.append('Retention does not purge obsolete empty Telephony threads')
for mapping in [('24h','HOURS.toMillis(24)'),('2d','DAYS.toMillis(2)'),('4d','DAYS.toMillis(4)'),('7d','DAYS.toMillis(7)'),('14d','DAYS.toMillis(14)')]:
    if f'"{mapping[0]}"' not in retention or mapping[1] not in retention:
        errors.append(f'Incorrect/missing retention mapping {mapping[0]}')
if 'public static final String OFF="off"' not in retention:
    errors.append('OFF is not the retention default')
if '.setPersisted(true)' not in retention or '.setPeriodic(PERIOD_MS)' not in retention:
    errors.append('Retention periodic persisted job missing')
if errors:
    print('LEMENZO MESSAGES SETTINGS/RETENTION VALIDATION: FAIL')
    for e in errors: print('-',e)
    sys.exit(1)
print('LEMENZO MESSAGES SETTINGS/RETENTION VALIDATION: PASS')
print('- shared Lemenzo communication Settings design')
print('- custom non-grey dialogs')
print('- visible Off/24h/2d/4d/7d/14d choices')
print('- selected-state indication')
print('- immediate retention apply')
print('- obsolete-thread cleanup')
print('- persisted periodic retention')
