<?php
declare(strict_types=1);

$root = dirname(__DIR__);
$repo = file_get_contents($root . '/app/Repositories/SpecialtyFinanceRepository.php');
$controller = file_get_contents($root . '/app/Controllers/SpecialtyFinanceController.php');

$result = [
    'schema' => 'DDB_SPECIALTY_FINANCE_FAIR_COMPARISON_STATIC_AUDIT_V1',
    'captured_at' => date(DATE_ATOM),
    'contracts' => [
        'year_only_predicate_count' => preg_match_all('/WHERE\s+YEARID\s*=\s*:year/iu', $repo, $m1),
        'yearid_reference_count' => preg_match_all('/YEARID/iu', $repo, $m2),
        'fair_policy_reference_count' => preg_match_all('/FairYearComparisonPolicy/iu', $controller . $repo, $m3),
        'month_filter_reference_count' => preg_match_all('/MONTH(ID|_ID)|last_complete_month/iu', $controller . $repo, $m4),
        'specialty_summary_calls' => preg_match_all('/annualMetricTotal\(/u', $repo, $m5),
        'specialty_ranking_calls' => preg_match_all('/specialty(Ranking|Matrix|NetRevenueRanking|TotalRevenueRanking)\(/u', $repo, $m6),
    ],
    'finding' => 'Current Specialty Finance implementation is year-grain only until a real monthly/date column is proven.',
    'source_changes' => 'NONE',
    'oracle_writes' => 'NONE',
];

echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
