<?php

use App\Models\MediaMonitoring;
use App\Models\Theme;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

describe('MediaMonitoring Model', function () {
    it('can create a media monitoring entry', function () {
        $mediaMonitoring = MediaMonitoring::factory()->create([
            'title' => 'Test Media Title',
            'media_name' => 'Test Media',
        ]);

        expect($mediaMonitoring->title)->toBe('Test Media Title')
            ->and($mediaMonitoring->media_name)->toBe('Test Media')
            ->and($mediaMonitoring->exists)->toBeTrue();
    });

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

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

    it('has themes relationship', function () {
        $mediaMonitoring = MediaMonitoring::factory()->create();

        expect($mediaMonitoring->themes())->toBeInstanceOf(BelongsToMany::class);
    });

    it('has issue management relationship', function () {
        $mediaMonitoring = MediaMonitoring::factory()->create();

        expect($mediaMonitoring->issueManagement())->toBeInstanceOf(HasOne::class);
    });

    it('can attach themes', function () {
        $mediaMonitoring = MediaMonitoring::factory()->create();
        $theme = Theme::factory()->create();

        $mediaMonitoring->themes()->attach($theme->id);

        expect($mediaMonitoring->themes)->toHaveCount(1)
            ->and($mediaMonitoring->themes->first()->id)->toBe($theme->id);
    });
});
