<?php

use App\Enums\IssueSentiment;
use App\Models\IssueManagement;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

describe('IssueManagement Model', function () {
    it('can create an issue management entry', function () {
        $issue = IssueManagement::factory()->create([
            'description' => 'Test Issue Description',
            'issue' => IssueSentiment::POSITIVE,
            'response' => IssueSentiment::POSITIVE,
        ]);

        expect($issue->description)->toBe('Test Issue Description')
            ->and($issue->issue)->toBe(IssueSentiment::POSITIVE)
            ->and($issue->response)->toBe(IssueSentiment::POSITIVE)
            ->and($issue->exists)->toBeTrue();
    });

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

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

    it('belongs to location', function () {
        $issue = IssueManagement::factory()->create();

        expect($issue->location())->toBeInstanceOf(BelongsTo::class);
    });

    it('belongs to sub location', function () {
        $issue = IssueManagement::factory()->create();

        expect($issue->subLocation())->toBeInstanceOf(BelongsTo::class);
    });

    it('belongs to classification', function () {
        $issue = IssueManagement::factory()->create();

        expect($issue->classification())->toBeInstanceOf(BelongsTo::class);
    });

    it('belongs to sub classification', function () {
        $issue = IssueManagement::factory()->create();

        expect($issue->subClassification())->toBeInstanceOf(BelongsTo::class);
    });

    it('belongs to media monitoring', function () {
        $issue = IssueManagement::factory()->create();

        expect($issue->mediaMonitoring())->toBeInstanceOf(BelongsTo::class);
    });

    it('casts sentiment enums correctly', function () {
        $issue = IssueManagement::factory()->create([
            'issue' => IssueSentiment::NEGATIVE,
            'response' => IssueSentiment::POSITIVE,
        ]);

        expect($issue->issue)->toBeInstanceOf(IssueSentiment::class)
            ->and($issue->issue)->toBe(IssueSentiment::NEGATIVE)
            ->and($issue->response)->toBeInstanceOf(IssueSentiment::class)
            ->and($issue->response)->toBe(IssueSentiment::POSITIVE);
    });
});
