<?php

namespace Tests\Unit\Services\Inventory;

use App\Services\Inventory\InventoryContextService;
use App\Services\Inventory\InventorySummaryService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class InventorySummaryServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_summary_returns_items(): void
    {
        $this->seedConfig();
        $this->seedItem();

        $service = new InventorySummaryService(new InventoryContextService());
        $result = $service->summary('classroom', '2025-2026');

        $this->assertNotEmpty($result['items']);
    }

    private function seedConfig(): void
    {
        DB::table('configuration')->insert([
            ['config_key' => 'school_year', 'config_value' => '2025-2026'],
            ['config_key' => 'semester', 'config_value' => 'Fall'],
        ]);
    }

    private function seedItem(): void
    {
        $categoryId = DB::table('inventory_categories')->insertGetId([
            'type' => 'classroom',
            'name' => 'Classroom',
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        DB::table('inventory_items')->insert([
            'type' => 'classroom',
            'category_id' => $categoryId,
            'name' => 'Item',
            'quantity' => 2,
            'semester' => 'Fall',
            'school_year' => '2025-2026',
            'created_at' => now(),
            'updated_at' => now(),
        ]);
    }
}
