<?php

namespace Modules\Payment\Providers;

use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use Modules\Payment\Enums\PaymentMethod;
use Modules\Payment\Events\PaymentCompleted;
use Modules\Payment\Events\RefundProcessed;
use Modules\Payment\Factories\PaymentGatewayFactory;
use Modules\Payment\Gateways\KbzMiniAppGateway;
use Modules\Payment\Listeners\MarkBookingPaid;
use Modules\Payment\Listeners\MarkBookingRefunded;
use Modules\Payment\Models\Payment;
use Modules\Payment\Observers\PaymentObserver;

class PaymentServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->singleton(PaymentGatewayFactory::class, function (): PaymentGatewayFactory {
            $factory = new PaymentGatewayFactory;
            $factory->register(PaymentMethod::KbzMiniApp, KbzMiniAppGateway::class);

            return $factory;
        });
    }

    public function boot(): void
    {
        Event::listen(PaymentCompleted::class, MarkBookingPaid::class);
        Event::listen(RefundProcessed::class, MarkBookingRefunded::class);

        Payment::observe(PaymentObserver::class);
    }
}
