<?php

namespace Tests\Unit\Services\Finance;

use App\Services\Finance\FinancialSchoolYearService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class FinancialSchoolYearServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_list_years_returns_distinct_sorted_years(): void
    {
        DB::table('invoices')->insert([
            [
                'id' => 1,
                'parent_id' => 1,
                'invoice_number' => 'INV-100',
                'total_amount' => 10,
                'balance' => 10,
                'paid_amount' => 0,
                'has_discount' => 0,
                'issue_date' => '2024-01-01',
                'due_date' => '2024-02-01',
                'status' => 'unpaid',
                'school_year' => '2024-2025',
            ],
            [
                'id' => 2,
                'parent_id' => 1,
                'invoice_number' => 'INV-101',
                'total_amount' => 10,
                'balance' => 10,
                'paid_amount' => 0,
                'has_discount' => 0,
                'issue_date' => '2025-01-01',
                'due_date' => '2025-02-01',
                'status' => 'unpaid',
                'school_year' => '2025-2026',
            ],
        ]);

        $service = new FinancialSchoolYearService();
        $years = $service->listYears();

        $this->assertSame(['2025-2026', '2024-2025'], $years);
    }
}
