<?php

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

uses(RefreshDatabase::class);

test('classification has correct fillable/guarded properties', function () {
    $classification = new Classification;

    expect($classification->getGuarded())->toBe(['id']);
});

test('classification has correct casts', function () {
    $classification = new Classification;

    expect($classification->getCasts())->toHaveKey('is_active', IsActive::class);
    expect($classification->getCasts())->toHaveKey('deleted_at', 'datetime');
});

test('classification can be created using factory', function () {
    $classification = Classification::factory()->create([
        'name' => 'Test Classification',
    ]);

    expect($classification->name)->toBe('Test Classification');
    $this->assertDatabaseHas('classifications', [
        'id' => $classification->id,
        'name' => 'Test Classification',
    ]);
});

test('classification active scope filters correctly', function () {
    Classification::factory()->count(3)->active()->create();
    Classification::factory()->count(2)->inactive()->create();

    expect(Classification::active()->count())->toBe(3);
});

test('classification inactive scope filters correctly', function () {
    Classification::factory()->count(3)->active()->create();
    Classification::factory()->count(2)->inactive()->create();

    expect(Classification::inactive()->count())->toBe(2);
});

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

    // We need SubClassification factory for this, but let's just check the relation type for now
    // or create a quick test without factory if it's not ready.
    expect($classification->subClassifications())->toBeInstanceOf(HasMany::class);
});
