<?php

namespace Tests\Unit\Services;

use App\Services\QuestionServiceApi;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;

class QuestionServiceApiTest extends TestCase
{
    public function test_list_questions_passes_filters_correctly()
    {
        Http::fake([
            '*/questions*' => Http::response(['data' => [], 'meta' => []], 200),
        ]);

        $service = new QuestionServiceApi();
        
        $filters = [
            'kp_code' => 'KP1001',
            'difficulty' => '0.5',
            'type' => 'CHOICE', // New filter
            'search' => 'test',
        ];

        $service->listQuestions(1, 10, $filters);

        Http::assertSent(function ($request) {
            return isset($request['kp_code']) && $request['kp_code'] === 'KP1001' &&
                   isset($request['difficulty']) && $request['difficulty'] === '0.5' &&
                   isset($request['type']) && $request['type'] === 'CHOICE' &&
                   isset($request['search']) && $request['search'] === 'test';
        });
    }

    public function test_generate_questions_passes_new_parameters()
    {
        Http::fake([
            '*/questions/generate*' => Http::response(['success' => true], 200),
        ]);

        $service = new QuestionServiceApi();
        
        $params = [
            'kp_code' => 'KP1001',
            'count' => 5,
            'difficulty' => '0.8', // New param
            'type' => 'CALCULATION', // New param
        ];

        $service->generateQuestions($params);

        Http::assertSent(function ($request) {
            return $request['difficulty'] === '0.8' &&
                   $request['type'] === 'CALCULATION';
        });
    }
}
