#!/usr/bin/env php
<?php

declare(strict_types=1);

use Cli\CliTester;

require_once __DIR__ . "/../vendor/autoload.php";

$options = getopt('' , ['file:','verbose']);
if (!isset($options['file'])) {
    exit("ERROR: Unknown csv path. Please put csv path to \"--file\" option." . PHP_EOL);
}

$csvPath = realpath($options['file']);
if ($csvPath === false) {
    exit("ERROR: Unknown csv path: $csvPath" . PHP_EOL);
}

$isVerbose = array_key_exists( 'verbose', $options);

$tester = new CliTester($csvPath);
$tester->test();
foreach ($tester->test() as $state => $message) {
    if ($isVerbose && !$state) {
        echo $message . PHP_EOL;
    }
}

$accuracy = number_format($tester->getAccuracy(), 2);
[$correct, $total] = $tester->getCounts();
$delta = $total - $correct;
$templates = implode(PHP_EOL, $tester->getTemplates());
$result = <<<TEXT
    
    TESTED TEMPLATES:
    $templates
    
    ACCURACY: $accuracy
    COUNT CASE TOTAL: $total
    COUNT CASE PASS:  $correct
    COUNT CASE ERROR: $delta
    
    TEXT;

echo $result;