<?php

use App\Enums\IsActive;
use App\Models\Classification;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

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

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

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

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

    it('has sub classifications relationship', function () {
        $classification = Classification::factory()->create();

        expect($classification->subClassifications())->toBeInstanceOf(HasMany::class);
    });

    it('has content recaps relationship', function () {
        $classification = Classification::factory()->create();

        expect($classification->contentRecaps())->toBeInstanceOf(HasMany::class);
    });

    it('scopes active classifications', function () {
        Classification::factory()->create(['is_active' => IsActive::ACTIVE]);
        Classification::factory()->create(['is_active' => IsActive::INACTIVE]);

        $activeClassifications = Classification::active()->get();

        expect($activeClassifications)->toHaveCount(1)
            ->and($activeClassifications->first()->is_active)->toBe(IsActive::ACTIVE);
    });

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

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