<?php

namespace Tests\Unit;

use App\Services\FeeCalculator;
use PHPUnit\Framework\TestCase;

/**
 * Verifica la regla de comisión por defecto (sin Laravel): cuota fija + % sobre el precio base del organizador.
 *
 * @see \App\Services\FeeCalculator
 */
class FeeCalculatorTest extends TestCase
{
    public function test_precio_base_25_calcula_fee_y_total_al_comprador(): void
    {
        $fee = FeeCalculator::calculate(25.00);

        $this->assertSame(25.00, $fee['organizer_net']);
        $this->assertSame(4.24, $fee['platform_fee']);
        $this->assertSame(29.24, $fee['user_total']);
    }

    public function test_precio_base_100(): void
    {
        $fee = FeeCalculator::calculate(100.00);

        $this->assertSame(7.99, $fee['platform_fee']);
        $this->assertSame(100.00, $fee['organizer_net']);
        $this->assertSame(107.99, $fee['user_total']);
    }

    public function test_precio_base_cero_no_genera_fee(): void
    {
        $fee = FeeCalculator::calculate(0.00);

        $this->assertSame(0.0, $fee['platform_fee']);
        $this->assertSame(0.0, $fee['organizer_net']);
        $this->assertSame(0.0, $fee['user_total']);
    }

    public function test_precio_base_negativo_se_normaliza_a_cero(): void
    {
        $fee = FeeCalculator::calculate(-15.50);

        $this->assertSame(0.0, $fee['organizer_net']);
        $this->assertSame(0.0, $fee['platform_fee']);
        $this->assertSame(0.0, $fee['user_total']);
    }

    public function test_redondeo_a_dos_decimales(): void
    {
        // 33.33 × 0.05 = 1.6665 → round → 1.67; total fee = 2.99 + 1.67 = 4.66
        $fee = FeeCalculator::calculate(33.33);

        $this->assertSame(4.66, $fee['platform_fee']);
        $this->assertSame(33.33, $fee['organizer_net']);
        $this->assertSame(37.99, $fee['user_total']);
    }
}
