<?php

declare(strict_types=1);

use App\Services\Supplier\Dto\SupplierProjectDto;
use App\Services\Supplier\SupplierPortalClient;
use Illuminate\Support\Facades\Http;

it('multi-flag save returns external_id per platform via listProjects', function (): void {
    Http::fake([
        '*/admin/visit/rt-project-save' => Http::response(['status' => 'OK', 'id' => '300'], 200),
        // Real portal returns name='B1_<identifier>' with the identifier in 'content'.
        '*/admin/visit/rt-projects-load*' => Http::response(['projects' => [
            ['id' => '100', 'name' => 'B1_okna.ru', 'content' => 'okna.ru', 'tag' => 'Москва', 'src' => 'rt'],
            ['id' => '200', 'name' => 'B2_okna.ru', 'content' => 'okna.ru', 'tag' => 'Москва', 'src' => 'bl'],
            ['id' => '300', 'name' => 'B3_okna.ru', 'content' => 'okna.ru', 'tag' => 'Москва', 'src' => 'mt'],
            ['id' => '999', 'name' => 'B1_other.ru', 'content' => 'other.ru', 'tag' => 'Москва', 'src' => 'rt'],
        ]], 200),
    ]);

    $dto = new SupplierProjectDto(
        platform: 'B1', signalType: 'site', uniqueKey: 'okna.ru', limit: 9,
        workdays: [1, 2, 3, 4, 5, 6, 7], regions: [82], regionsReverse: false, status: 'active',
        tag: 'Москва', platforms: ['B1', 'B2', 'B3'],
    );

    $ids = app(SupplierPortalClient::class)->saveProjectMultiFlag($dto);

    expect($ids)->toBe(['B1' => 100, 'B2' => 200, 'B3' => 300]);
});
