<?php

namespace App\Observers\Environment;

use App\Models\User;

use App\Models\Modules\Audits\Audit;
use App\Models\Hotel\Reservation;

class UserObserver
{
    public function deleting(User $user): void
    {
        // Avoid Delete Default User
        if (in_array($user->id, [1]))
            throw new \Exception("Default user cannot be Deleted.");

        // Save Relationships
        Audit::where('receptionist_id', $user->id)->update(['receptionist_id' => 1]);
        Reservation::where('receptionist_id', $user->id)->update(['receptionist_id' => 1]);
    }
}
