<?php

declare(strict_types=1);

use App\Services\Supplier\Import\SupplierImportMapper;
use Tests\TestCase;

uses(TestCase::class);

test('platformFromSrc maps rt/bl/mt to B1/B2/B3, others null', function (): void {
    expect(SupplierImportMapper::platformFromSrc('rt'))->toBe('B1');
    expect(SupplierImportMapper::platformFromSrc('bl'))->toBe('B2');
    expect(SupplierImportMapper::platformFromSrc('mt'))->toBe('B3');
    expect(SupplierImportMapper::platformFromSrc('dop2'))->toBeNull();
    expect(SupplierImportMapper::platformFromSrc(''))->toBeNull();
});

test('signalTypeFromType maps calls/hosts/sms', function (): void {
    expect(SupplierImportMapper::signalTypeFromType('calls'))->toBe('call');
    expect(SupplierImportMapper::signalTypeFromType('hosts'))->toBe('site');
    expect(SupplierImportMapper::signalTypeFromType('sms'))->toBe('sms');
    expect(SupplierImportMapper::signalTypeFromType('unknown'))->toBeNull();
});

test('parseGibddRegions splits comma/space string of codes; empty → []', function (): void {
    expect(SupplierImportMapper::parseGibddRegions('24'))->toBe([24]);
    expect(SupplierImportMapper::parseGibddRegions('24,77'))->toBe([24, 77]);
    expect(SupplierImportMapper::parseGibddRegions('24, 77 78'))->toBe([24, 77, 78]);
    expect(SupplierImportMapper::parseGibddRegions(''))->toBe([]);
    expect(SupplierImportMapper::parseGibddRegions(null))->toBe([]);
});

test('workdaysToMask converts string day list to bitmask (bit0=Mon)', function (): void {
    expect(SupplierImportMapper::workdaysToMask(['1', '2', '3', '4', '5']))->toBe(31);
    expect(SupplierImportMapper::workdaysToMask(['1', '2', '3', '4', '5', '6', '7']))->toBe(127);
    expect(SupplierImportMapper::workdaysToMask([]))->toBe(127);
});

test('parseSmsContent splits sender+keyword; sender-only when no plus', function (): void {
    expect(SupplierImportMapper::parseSmsContent('79001234567+KVARTIRA'))
        ->toBe(['sender' => '79001234567', 'keyword' => 'KVARTIRA']);
    expect(SupplierImportMapper::parseSmsContent('79001234567'))
        ->toBe(['sender' => '79001234567', 'keyword' => null]);
    expect(SupplierImportMapper::parseSmsContent(''))
        ->toBe(['sender' => '', 'keyword' => null]);
});
