<?php

declare(strict_types=1);

namespace App\Observers;

use App\Models\DisciplinaryReport;
use App\Models\User;
use App\Notifications\DisciplinaryReportCreatedNotification;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Notification;

class DisciplinaryReportObserver
{
    public function creating(DisciplinaryReport $report): void
    {
        if ($report->created_by === null) {
            $report->created_by = Auth::id();
        }
    }

    public function created(DisciplinaryReport $report): void
    {
        Notification::send(
            User::role('hr_manager')->get(),
            new DisciplinaryReportCreatedNotification($report),
        );
    }
}
