<?php

namespace App\Listeners;

use App\Events\ContentModerated;
use App\Models\PlayerRecord;
use App\Models\PlayerVideo;
use App\Notifications\RecordModerationResultNotification;
use App\Notifications\VideoModerationResultNotification;

class SendContentModerationNotification
{
    public bool $afterCommit = true;

    public function handle(ContentModerated $event): void
    {
        $content = $event->content->loadMissing(['playerProfile.user']);

        if ($content instanceof PlayerRecord) {
            $content->playerProfile->user->notify(new RecordModerationResultNotification($content));

            return;
        }

        if ($content instanceof PlayerVideo) {
            $content->playerProfile->user->notify(new VideoModerationResultNotification($content));
        }
    }
}
