<?php
declare(strict_types=1);

namespace PpPhp\Core\Designer\Architecture\Validation;

use PpPhp\Core\Designer\Architecture\DesignerRuntimeContractReview;
use PpPhp\Core\Designer\Architecture\DesignerRuntimeLock;

final class DesignerArchitectureVerifier
{
    public function verify(): array
    {
        $review = (new DesignerRuntimeContractReview())->review();
        $lock = (new DesignerRuntimeLock())->create($review);

        $checks = [
            'contracts' => ($review['summary']['contracts'] ?? 0) >= 14,
            'review' => ($review['ok'] ?? false) === true,
            'lock' => ($lock['status'] ?? '') === 'LOCKED',
            'score' => ($lock['score'] ?? 0) === 100,
            'runtimeChain' => count($lock['runtimeChain'] ?? []) >= 14,
        ];

        $issues = [];
        foreach ($checks as $check => $ok) {
            if (!$ok) {
                $issues[] = ['check' => $check, 'message' => 'Designer architecture verification failed: ' . $check];
            }
        }

        return [
            'ok' => !in_array(false, $checks, true),
            'checks' => $checks,
            'issues' => $issues,
            'review' => $review,
            'lock' => $lock,
            'summary' => [
                'checks' => count($checks),
                'passed' => count(array_filter($checks)),
                'failed' => count($checks) - count(array_filter($checks)),
                'contracts' => $review['summary']['contracts'] ?? 0,
                'score' => in_array(false, $checks, true) ? 80 : 100,
                'status' => $lock['status'] ?? 'FAILED',
            ],
        ];
    }
}
