<?php

namespace MintyPHP\Tests\Architecture;

use PHPUnit\Framework\TestCase;

class PublicPageRoutingContractTest extends TestCase
{
    use ProjectFileAssertionSupport;

    public function testPublicStaticPageRoutesPointToPublicPageTargets(): void
    {
        $routes = include dirname(__DIR__, 2) . '/config/routes.php';
        $this->assertIsArray($routes);

        $byPath = [];
        foreach ($routes as $route) {
            if (!is_array($route)) {
                continue;
            }
            $path = trim((string) ($route['path'] ?? ''));
            if ($path === '') {
                continue;
            }
            $byPath[$path] = $route;
        }

        foreach (['imprint', 'privacy', 'terms'] as $slug) {
            $this->assertArrayHasKey($slug, $byPath);
            $this->assertSame('public-page/' . $slug, (string) ($byPath[$slug]['target'] ?? ''));
            $this->assertTrue((bool) ($byPath[$slug]['public'] ?? false));
        }
    }

    public function testPageTemplatesAreSeparatedByContext(): void
    {
        $root = dirname(__DIR__, 2);

        $this->assertFileExists($root . '/pages/page/index(default).phtml');
        $this->assertFileDoesNotExist($root . '/pages/page/index(page).phtml');
        $this->assertFileExists($root . '/pages/public-page/index(page).phtml');
    }
}
