<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Event;
use App\Jobs\SendToGoogleJob;

class GoogleDataSyncServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        Event::listen('eloquent.saved: *', function ($eventName, array $data) {
            $model = $data[0];
            $modelName = strtolower(class_basename($model));
           // $allowedModelNames = ['appointments', 'controlhistory', 'history', 'patients', 'sectionhistory', 'physicalexam'];
           // if (in_array($modelName, $allowedModelNames)) {
                SendToGoogleJob::dispatch($model);
           // }            
        });
    }
}
