"""Sentinel V6 structural smoke checks."""
from pathlib import Path

from sentinel.api.app import app, v6_services

ROOT = Path(__file__).resolve().parents[1]

assert app.version == "7.0.0"
paths = {getattr(route, "path", "") for route in app.routes}
required = {
    "/administration",
    "/configuration",
    "/api/system/version",
    "/api/system/diagnostics",
    "/api/system/backup",
    "/api/equipment/{equipment_id}/calibrations",
    "/api/equipment/{equipment_id}/sensors",
    "/api/simulation/demo-fleet",
    "/reports/export/monitoring/{equipment_id}.csv",
    "/reports/export/alarms/{equipment_id}.csv",
    "/reports/export/technical/{equipment_id}.json",
    "/reports/export/predictive/{equipment_id}.json",
    "/reports/print/{equipment_id}",
    "/api/alarm-recipients",
    "/api/alarm-schedules/{schedule_id}",
}
missing = required - paths
assert not missing, f"Missing V6 routes: {sorted(missing)}"

for relative in ("templates/dashboard.html", "templates/monitoring_console.html"):
    text = (ROOT / relative).read_text(encoding="utf-8").lower()
    assert "coming soon" not in text

backup = v6_services.build_backup()
assert backup.exists() and backup.stat().st_size > 0
backup.unlink(missing_ok=True)
print("Sentinel V6 structural checks: OK")

assert "sensor_id" in (ROOT / "sentinel/v6_services.py").read_text(encoding="utf-8")
assert "Simulation lab" in (ROOT / "templates/monitoring_console.html").read_text(encoding="utf-8")
assert "Configure alarm rules" in (ROOT / "templates/monitoring_console.html").read_text(encoding="utf-8")

admin_template=(ROOT / "templates/monitoring_console.html").read_text(encoding="utf-8")
assert 'data-admin-tab="simulation"' in admin_template
assert 'data-admin-panel="simulation"' in admin_template
assert 'Sentinel Platform V7.0' in admin_template
assert 'V5.8' not in admin_template
js=(ROOT / "static/js/monitoring-console.js").read_text(encoding="utf-8")
assert 'data.version !== "7.0.0"' in js
print("Sentinel V6.4 compatibility + V7 UI checks: OK")

assert "alarm_resolution_locks" in (ROOT / "sentinel/monitoring/store.py").read_text(encoding="utf-8")
assert "alarm_notifications" in (ROOT / "sentinel/monitoring/store.py").read_text(encoding="utf-8")
assert "alarm-detail-row" in admin_template
assert "Equipment memberships" in admin_template
assert (ROOT / "templates/equipment_offline.html").exists()
