<?php

namespace App\Observers;

use App\Listeners\SyncRestoreRunToOperationRun;
use App\Models\RestoreRun;

class RestoreRunObserver
{
    /**
     * Handle the RestoreRun "created" event.
     */
    public function created(RestoreRun $restoreRun): void
    {
        $this->sync($restoreRun);
    }

    /**
     * Handle the RestoreRun "updated" event.
     */
    public function updated(RestoreRun $restoreRun): void
    {
        $this->sync($restoreRun);
    }

    protected function sync(RestoreRun $restoreRun): void
    {
        /** @var SyncRestoreRunToOperationRun $syncer */
        $syncer = app(SyncRestoreRunToOperationRun::class);
        $syncer->handle($restoreRun);
    }
}
