#!/usr/bin/env python3
"""Dependency-free static checks; does NOT replace CodeIgniter runtime or security tests."""
from pathlib import Path
import json

root = Path(__file__).resolve().parents[1]
required = [
  'composer.json', 'app/Config/Paths.php', 'app/Config/Boot/development.php',
  'app/Config/Boot/production.php', 'app/Config/Routes.php',
  'app/Config/Routes/TenantRoutes.php', 'app/Config/Routes/PlatformRoutes.php',
  'app/Config/Routes/PublicRoutes.php', 'app/Config/Hive/ModuleRoutes.php',
  'app/Views/layouts/tenant.php','app/Views/layouts/platform.php',
  'app/Views/layouts/public.php','app/Views/layouts/auth.php',
  'app/Views/partials/header.php','app/Views/partials/sidebar.php',
  'app/Views/partials/footer.php','app/Views/partials/modals.php',
  'app/Views/partials/head.php', 'app/Views/components/page_heading.php',
  'app/Views/auth/tenant_login.php','app/Views/auth/platform_login.php',
  'app/Views/public_site/home.php','modules/Example/Config/Routes.php',
  'modules/Example/Views/index.php','public/assets/css/app.css',
  'public/assets/css/ui-refinements.css','public/assets/css/components/hive-ui.css','public/assets/css/hive-shell.css',
  'public/assets/vendor/lucide.min.js','public/assets/js/core/hive-shell.js',
  'resources/standard-template/hive-ui-step-06-v1.6.1/assets/js/routes.js',
  'resources/standard-template/hive-ui-step-06-v1.6.1/assets/js/standalone.js',
  'resources/standard-template/SCREEN-CATALOG.md',
]
for item in required:
    assert (root/item).is_file(), f'Missing {item}'
config = json.loads((root/'composer.json').read_text())
assert 'codeigniter4/framework' in config['require']
assert 'Modules\\' in config['autoload']['psr-4']
routes = (root/'app/Config/Routes.php').read_text()
assert '$routes->setAutoRoute(false);' in routes
assert "ENVIRONMENT === 'development'" in routes
assert "['filter' => 'tenant-auth']" in (root/'app/Config/Routes/TenantRoutes.php').read_text()
assert "['filter' => 'platform-auth']" in (root/'app/Config/Routes/PlatformRoutes.php').read_text()
assert 'setStatusCode(503)' in (root/'app/Controllers/Auth/TenantLoginController.php').read_text()
assert 'setStatusCode(503)' in (root/'app/Controllers/Auth/PlatformLoginController.php').read_text()
assert 'standalone.js' not in (root/'app/Views/partials/head.php').read_text()
for x in ['tenant','platform']:
    layout=(root/f'app/Views/layouts/{x}.php').read_text()
    for part in ['partials/sidebar','partials/header','partials/footer',"renderSection('content')"]:
        assert part in layout, (x,part)
assert len(list((root/'resources/standard-template/hive-ui-step-06-v1.6.1').rglob('*.html'))) == 13
assert len(list((root/'modules').iterdir())) == 1, 'Only the Example module should exist'
print(f'PASS: {len(required)} foundation files, route guards, layouts, preserved prototype, 1 Example module.')
print('Reminder: Composer/framework installation is needed for CI4 runtime testing.')
