<?php

namespace MintyPHP\Tests\Architecture;

trait CodexDocsContractSupport
{
    /**
     * @return list<string>
     */
    private function filesCoveredByDocsLinkIntegrityCheck(): array
    {
        $root = dirname(__DIR__, 2);
        $files = ['README.md'];
        $scanDirs = ['docs', '.agents'];

        foreach ($scanDirs as $scanDir) {
            $directory = new \RecursiveDirectoryIterator(
                $root . '/' . $scanDir,
                \FilesystemIterator::SKIP_DOTS
            );
            $iterator = new \RecursiveIteratorIterator($directory);

            foreach ($iterator as $fileInfo) {
                if (!$fileInfo->isFile()) {
                    continue;
                }

                $fullPath = str_replace('\\', '/', $fileInfo->getPathname());
                if (!str_ends_with($fullPath, '.md')) {
                    continue;
                }

                $relative = ltrim(str_replace(str_replace('\\', '/', $root), '', $fullPath), '/');
                if (str_starts_with($relative, '.agents/runs/')) {
                    continue;
                }

                $files[] = $relative;
            }
        }

        $files = array_values(array_unique($files));
        sort($files);
        return $files;
    }
}
