<?php

use App\Enums\IsActive;
use App\Models\SubClassification;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

describe('SubClassification Model', function () {
    it('can create a sub classification', function () {
        $subClassification = SubClassification::factory()->create([
            'name' => 'Test Sub Classification',
        ]);

        expect($subClassification->name)->toBe('Test Sub Classification')
            ->and($subClassification->exists)->toBeTrue();
    });

    it('has guarded attributes', function () {
        $guarded = ['id'];

        expect(SubClassification::make()->getGuarded())->toEqual($guarded);
    });

    it('belongs to classification', function () {
        $subClassification = SubClassification::factory()->create();

        expect($subClassification->classification())->toBeInstanceOf(BelongsTo::class);
    });

    it('casts is_active to enum', function () {
        $subClassification = SubClassification::factory()->create(['is_active' => IsActive::ACTIVE]);

        expect($subClassification->is_active)->toBeInstanceOf(IsActive::class)
            ->and($subClassification->is_active)->toBe(IsActive::ACTIVE);
    });
});
