<?php

use App\Models\BarberStore;
use CodeIgniter\Test\CIUnitTestCase;

final class BarberStoreTest extends CIUnitTestCase
{
    public function testCanStoreServicesAndTransactions(): void
    {
        $file = WRITEPATH . 'test-barber-data.json';
        if (file_exists($file)) {
            unlink($file);
        }

        $store = new BarberStore($file);

        $store->saveServices([
            ['id' => 'cut', 'name' => 'Potong Rambut', 'price' => 60000],
        ]);

        $store->addTransaction([
            'id' => 'TRX-1',
            'customer' => 'Budi',
            'cashier' => 'Kasir',
            'items' => [['name' => 'Potong Rambut', 'price' => 60000]],
            'total' => 60000,
            'time' => '10:00',
        ]);

        $data = $store->loadData();

        $this->assertCount(1, $data['services']);
        $this->assertSame('Potong Rambut', $data['services'][0]['name']);
        $this->assertCount(1, $data['transactions']);
        $this->assertSame(60000, $data['transactions'][0]['total']);
    }
}
