<?php

use App\Models\SmsProfile;
use App\Services\Sms\SmsClient;
use App\Services\Sms\SmsMessage;
use App\Services\Sms\SmsResult;
use App\Services\Sms\SmsService;

it('sends via service and creates a log', function () {
    $profile = SmsProfile::factory()->create([
        'api_username' => 'apiuser',
        'api_password' => 'apipass',
    ]);

    // Bind a fake client that always returns sent
    app()->instance(SmsClient::class, new class implements SmsClient
    {
        public function send(App\Models\SmsProfile $profile, SmsMessage $message): SmsResult
        {
            return new SmsResult(status: 'sent', providerMessageId: '99999');
        }

        public function getCreditBalance(App\Models\SmsProfile $profile): int
        {
            return 0;
        }

        public function getPriceQuotes(App\Models\SmsProfile $profile): array
        {
            return [];
        }
    });

    $sms = app(SmsService::class);
    $log = $sms->sendRaw($profile, '+38640111222', 'Hello');

    expect($log->id)->not->toBeNull();
    expect($log->profile_id)->toBe($profile->id);
    expect($log->status)->toBe('sent');
    expect($log->provider_message_id)->toBe('99999');
});
