<?php

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

uses(RefreshDatabase::class);

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

        expect($location->name)->toBe('Test Location')
            ->and($location->exists)->toBeTrue();
    });

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

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

    it('has sub locations relationship', function () {
        $location = Location::factory()->create();

        expect($location->subLocations())->toBeInstanceOf(HasMany::class);
    });

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

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