<?php

namespace App\Observers;

use App\Models\InstallRequest;
use App\Jobs\SendRequestTo1CJob;

class InstallRequestObserver
{
    /**
     * Handle the InstallRequest "created" event.
     */
    public function created(InstallRequest $installRequest): void
    {
        //
    }

    /**
     * Handle the InstallRequest "updated" event.
     */
    public function updated(InstallRequest $installRequest): void
    {
        // Проверяем, что статус изменился
        if (
            $installRequest->isDirty('status') &&
            $installRequest->status === 'done' &&
            !$installRequest->sent_to_1c
        ) {
            SendRequestTo1CJob::dispatch($installRequest->id);
        }
    }

    /**
     * Handle the InstallRequest "deleted" event.
     */
    public function deleted(InstallRequest $installRequest): void
    {
        //
    }

    /**
     * Handle the InstallRequest "restored" event.
     */
    public function restored(InstallRequest $installRequest): void
    {
        //
    }

    /**
     * Handle the InstallRequest "force deleted" event.
     */
    public function forceDeleted(InstallRequest $installRequest): void
    {
        //
    }
}
