from pathlib import Path

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


def read(relative_path: str) -> str:
    return (ROOT / relative_path).read_text()


def test_family_directory_markers_exist_across_doris_apps() -> None:
    expectations = {
        'doris-kitchen/app/templates/base.html': [
            'doris-family-shell',
            'doris-family-nav',
            'Singular front door',
            'Doris family directory',
            'Casefile directory',
            'family-directory-grid',
            'Doris Dashboard',
            'Services Directory',
            'Doris Schoolhouse',
            'Doris Barbell',
            'case-nav',
            'Queue board',
        ],
        'doris-schoolhouse/app/templates/base.html': [
            'doris-family-shell',
            'doris-family-nav',
            'Singular front door',
            'Doris family directory',
            'Casefile directory',
            'family-directory-grid',
            'Doris Dashboard',
            'Services Directory',
            'Doris Kitchen',
            'Doris Barbell',
            'case-nav',
            'Submission packet',
        ],
        'doris-barbell/app/templates/base.html': [
            'doris-family-shell',
            'doris-family-nav',
            'Singular front door',
            'Doris family directory',
            'Casefile directory',
            'family-directory-grid',
            'Doris Dashboard',
            'Services Directory',
            'Doris Kitchen',
            'Doris Schoolhouse',
            'case-nav',
            'Workout reports',
        ],
        'doris-dashboard/bin/generate_dashboard.py': [
            'render_family_directory',
            'Doris family directory',
            'Services Directory',
            'Doris Kitchen',
            'Doris Schoolhouse',
            'Doris Barbell',
            'family-directory-grid',
        ],
    }

    for relative_path, markers in expectations.items():
        content = read(relative_path)
        for marker in markers:
            assert marker in content, f'{marker} missing from {relative_path}'


def test_family_navigation_styles_exist() -> None:
    expectations = {
        'doris-kitchen/app/static/app.css': ['.doris-family-shell .case-nav', '.family-directory-grid', '.family-app-card', '.family-app-kicker'],
        'doris-schoolhouse/app/static/app.css': ['.doris-family-shell .case-nav', '.family-directory-grid', '.family-app-card', '.family-app-kicker'],
        'doris-barbell/app/static/app.css': ['.doris-family-shell .case-nav', '.family-directory-grid', '.family-app-card', '.family-app-kicker'],
        'doris-dashboard/public/style.css': ['.family-portal', '.family-directory-grid', '.family-app-card', '.family-app-kicker'],
    }

    for relative_path, markers in expectations.items():
        content = read(relative_path)
        for marker in markers:
            assert marker in content, f'{marker} missing from {relative_path}'


def test_hotfuzz_photo_assets_exist_and_are_wired() -> None:
    assets = {
        'doris-dashboard/public/assets/hotfuzz-operator-desk.jpg': 'Operator still · source logged in docs',
        'doris-barbell/app/static/images/hotfuzz-training-dossier.jpg': 'Training still · source logged in docs',
        'doris-kitchen/app/static/images/hotfuzz-pantry-evidence.jpg': 'Pantry still · source logged in docs',
        'doris-schoolhouse/app/static/images/hotfuzz-records-desk.jpg': 'Records still · source logged in docs',
    }

    for relative_path, marker in assets.items():
        assert (ROOT / relative_path).exists(), f'missing asset file: {relative_path}'
        if relative_path.startswith('doris-dashboard/'):
            content = read('doris-dashboard/bin/generate_dashboard.py')
        elif 'barbell' in relative_path:
            content = read('doris-barbell/app/templates/base.html')
        elif 'kitchen' in relative_path:
            content = read('doris-kitchen/app/templates/base.html')
        else:
            content = read('doris-schoolhouse/app/templates/base.html')
        assert Path(relative_path).name in content, f'{relative_path} not wired into template/generator'
        assert marker in content, f'{marker} missing where {relative_path} is referenced'

    provenance_doc = ROOT / 'doris-family-hotfuzz-graphics-sources-2026-05-24.md'
    assert provenance_doc.exists(), 'graphics provenance doc missing'
    provenance_text = provenance_doc.read_text()
    for marker in ['CC BY-SA', 'CC BY-NC-SA', 'CC BY-NC-ND', 'CC BY-NC']:
        assert marker in provenance_text, f'{marker} missing from provenance doc'


def test_barbell_interior_anchor_markers_exist() -> None:
    content = read('doris-barbell/app/templates/dashboard.html')
    for marker in ['id="body-metrics"', 'id="weight-log"', 'id="routine-board"', 'id="recent-workouts"']:
        assert marker in content, f'{marker} missing from Doris Barbell dashboard'
