<?php

use App\Enums\IsActive;
use App\Models\Theme;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

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

        expect($theme->name)->toBe('Test Theme')
            ->and($theme->exists)->toBeTrue();
    });

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

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

    it('has media monitorings relationship', function () {
        $theme = Theme::factory()->create();

        expect($theme->mediaMonitorings())->toBeInstanceOf(BelongsToMany::class);
    });

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

        $activeThemes = Theme::active()->get();

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

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

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