<?php

declare(strict_types=1);

namespace Tests\Unit;

use App\Support\Metric;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class MetricTest extends TestCase
{
    #[Test]
    public function ok_lleva_valor_y_sin_nota(): void
    {
        $m = Metric::ok(1500.0)->toArray();

        $this->assertSame(1500.0, $m['value']);
        $this->assertSame('ok', $m['state']);
        $this->assertNull($m['note']);
    }

    #[Test]
    public function no_data_no_lleva_valor_y_explica_por_que(): void
    {
        $m = Metric::noData('sin snapshot de hace 7 dias')->toArray();

        $this->assertNull($m['value']);
        $this->assertSame('no_data', $m['state']);
        $this->assertSame('sin snapshot de hace 7 dias', $m['note']);
    }

    #[Test]
    public function unreliable_conserva_el_valor_pero_advierte(): void
    {
        $m = Metric::unreliable(98.2, 'no hay costos registrados en el periodo')->toArray();

        $this->assertSame(98.2, $m['value']);
        $this->assertSame('unreliable', $m['state']);
        $this->assertSame('no hay costos registrados en el periodo', $m['note']);
    }

    #[Test]
    public function ok_conserva_la_tendencia(): void
    {
        $trend = ['trend_pct' => 17.4, 'good' => true];

        $m = Metric::ok(5556701.0, $trend)->toArray();

        $this->assertSame($trend, $m['trend']);
    }

    #[Test]
    public function unreliable_conserva_la_tendencia(): void
    {
        $trend = ['trend_pct' => -57.5, 'good' => false];

        $m = Metric::unreliable(973500.0, 'la caja se esta drenando', $trend)->toArray();

        $this->assertSame($trend, $m['trend']);
    }

    #[Test]
    public function sin_tendencia_el_campo_viaja_null(): void
    {
        $this->assertNull(Metric::ok(1500.0)->toArray()['trend']);
        $this->assertNull(Metric::noData('sin base')->toArray()['trend']);
    }
}
