<?php

declare(strict_types=1);

use App\Services\DaData\DaDataException;
use App\Services\DaData\DaDataPhoneClient;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\Support\Imitation\FakeDaDataPhoneClient;

uses(DatabaseTransactions::class);

/**
 * Direct tests for FakeDaDataPhoneClient (TDD gate heuristic).
 * Integration tests are in FakeDaDataClientTest.php.
 * Task 1 — Phase 1 Portal Client Imitation Harness.
 */
it('fake phone client is subtype of DaDataPhoneClient', function (): void {
    expect(new FakeDaDataPhoneClient)->toBeInstanceOf(DaDataPhoneClient::class);
})->group('imitation');

it('stub method returns self for fluent chaining', function (): void {
    $fake = new FakeDaDataPhoneClient;
    $result = $fake->stub('79990000001', qc: 0, region: 'Москва', provider: 'МТС');
    expect($result)->toBeInstanceOf(FakeDaDataPhoneClient::class);
})->group('imitation');

it('cleanPhone throws DaDataException when no stub registered', function (): void {
    $fake = new FakeDaDataPhoneClient;
    expect(fn () => $fake->cleanPhone('79990000099'))->toThrow(DaDataException::class);
})->group('imitation');

it('stubThrows registers exception for cleanPhone', function (): void {
    $fake = new FakeDaDataPhoneClient;
    $fake->stubThrows('79990000002');
    expect(fn () => $fake->cleanPhone('79990000002'))->toThrow(DaDataException::class);
})->group('imitation');
