<?php

namespace Tests\Unit;

use App\Support\NigeriaPhone;
use PHPUnit\Framework\TestCase;

class NigeriaPhoneTest extends TestCase
{
    public function test_normalize_accepts_common_nigeria_formats(): void
    {
        $cases = [
            '+2347065620433' => '07065620433',
            '2347065620433' => '07065620433',
            '07065620433' => '07065620433',
            '0706 562 0433' => '07065620433',
            '+234 706 562 0433' => '07065620433',
            '(0706)-562-0433' => '07065620433',
        ];

        foreach ($cases as $input => $expected) {
            $this->assertSame($expected, NigeriaPhone::normalize($input), $input);
        }
    }

    public function test_normalize_rejects_invalid_values(): void
    {
        $this->assertNull(NigeriaPhone::normalize(''));
        $this->assertNull(NigeriaPhone::normalize('12345'));
        $this->assertNull(NigeriaPhone::normalize('0800000000'));
        $this->assertNull(NigeriaPhone::normalize('999999999999999'));
    }

    public function test_detect_network_returns_known_provider_or_unknown(): void
    {
        $this->assertSame('mtn', NigeriaPhone::detectNetwork('08035620433'));
        $this->assertSame('airtel', NigeriaPhone::detectNetwork('08025620433'));
        $this->assertSame('glo', NigeriaPhone::detectNetwork('08055620433'));
        $this->assertSame('9mobile', NigeriaPhone::detectNetwork('08095620433'));
        $this->assertSame('unknown', NigeriaPhone::detectNetwork('07005620433'));
    }

    public function test_validate_vtu_phone_respects_optional_network_match_rule(): void
    {
        $strict = NigeriaPhone::validateVtuPhoneNumber(
            '+2348056204333',
            'mtn',
            ['validate_network_match' => true]
        );
        $this->assertFalse($strict['is_valid']);
        $this->assertNotEmpty($strict['errors']);

        $lenient = NigeriaPhone::validateVtuPhoneNumber(
            '+2348056204333',
            'mtn',
            ['validate_network_match' => false]
        );
        $this->assertTrue($lenient['is_valid']);
        $this->assertNotEmpty($lenient['warnings']);
    }
}

