<?php

namespace App\Modules\Bookings;

use Illuminate\Support\Facades\Event;

class ServiceProvider extends \App\Modules\ServiceProvider
{
    public function register()
    {
        parent::register('bookings');
    }

    public function boot()
    {
        parent::boot('bookings');

        // Register model observers
        Task::observe(new TaskObserver());
        Order::observe(new TaskObserver());
        Onsite::observe(new TaskObserver());
        SaleLead::observe(new TaskObserver());
        Comment::observe(new CommentObserver());

        // Custom client observers
        // Task::observe(new SladeLegalEvents);
        Task::observe(new ZulipNotifications()); // Send notifications to Zulip
        Repair::observe(new ZulipNotifications()); // Send notifications to Zulip
        Support::observe(new ZulipNotifications()); // Send notifications to Zulip
        Onsite::observe(new ZulipNotifications()); // Send notifications to Zulip

        // Register Notifications Observers
        Task::observe(new TaskNotificationsObserver());
        Repair::observe(new TaskNotificationsObserver());
        Support::observe(new TaskNotificationsObserver());
        Onsite::observe(new TaskNotificationsObserver());
        Order::observe(new TaskNotificationsObserver());
        Message::observe(new MessageNotificationsObserver());

        Event::subscribe(new PartUpdating());
        Event::subscribe(new PartCreating());
        Event::subscribe(new PartDeleted());
        Event::subscribe(new PartReceived());
        Event::subscribe(new CompositePartsUpdated());

        Event::subscribe(new BuildConfirmed());
        Event::subscribe(new BuildDeleted());
        Event::subscribe(new BuildUpdating());
        Event::subscribe(new BuildCompleted());
        Event::subscribe(new BuildTemplateCloned());
        Event::subscribe(new BuildComponentReceived());
        Event::subscribe(new FeedbackReceived());

        // Register repository bindings
        $this->app->bind('App\Modules\Bookings\TaskRepositoryInterface', 'App\Modules\Bookings\repositories\TaskRepositoryEloquent');
        $this->app->bind('App\Modules\Bookings\KeychainRepositoryInterface', function($app) {
            return new \App\Modules\Bookings\KeychainRepositoryEloquent(new \App\Models\Keychain());
        });
    }
}
