<?php

namespace Tests\Unit\Services\Billing;

use App\Services\Billing\BillingTotalsService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class BillingTotalsServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_event_and_additional_subtotals(): void
    {
        DB::table('events')->insert([
            'id' => 1,
            'event_name' => 'Field Trip',
            'amount' => 25.00,
        ]);

        DB::table('event_charges')->insert([
            'id' => 1,
            'event_id' => 1,
            'parent_id' => 10,
            'charged' => 25.00,
            'school_year' => '2025-2026',
        ]);

        DB::table('additional_charges')->insert([
            [
                'id' => 1,
                'invoice_id' => 99,
                'parent_id' => 10,
                'school_year' => '2025-2026',
                'semester' => 'Fall',
                'charge_type' => 'add',
                'amount' => 15.00,
                'status' => 'applied',
            ],
            [
                'id' => 2,
                'invoice_id' => 99,
                'parent_id' => 10,
                'school_year' => '2025-2026',
                'semester' => 'Fall',
                'charge_type' => 'deduct',
                'amount' => 5.00,
                'status' => 'applied',
            ],
        ]);

        $service = new BillingTotalsService();

        $eventSubtotal = $service->eventSubtotal(10, '2025-2026');
        $additionalSubtotal = $service->additionalSubtotal(99, '2025-2026');

        $this->assertSame(25.0, $eventSubtotal);
        $this->assertSame(10.0, $additionalSubtotal);
    }
}
