<?php

namespace Tests\Unit\Services\Inventory;

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

class SupplierServiceTest extends TestCase
{
    use RefreshDatabase;

    public function test_create_supplier(): void
    {
        $service = new SupplierService();
        $result = $service->create([
            'name' => 'Supplier A',
            'email' => 'a@example.com',
        ]);

        $this->assertTrue($result['ok']);
        $this->assertDatabaseHas('suppliers', ['name' => 'Supplier A']);
    }

    public function test_update_supplier(): void
    {
        $id = DB::table('suppliers')->insertGetId([
            'name' => 'Supplier B',
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        $service = new SupplierService();
        $result = $service->update($id, ['name' => 'Supplier Updated']);

        $this->assertTrue($result['ok']);
        $this->assertDatabaseHas('suppliers', ['id' => $id, 'name' => 'Supplier Updated']);
    }
}
