<?php

namespace Mehrab\Payment\Providers;

use Illuminate\Support\Facades\Gate;
use Mehrab\Payment\Gateways\Gateway;
use Mehrab\Payment\Gateways\Nextpay\NextpayAdaptor;
use Mehrab\Payment\Models\Payment;
use Mehrab\Payment\Policies\PaymentPolicy;
use Mehrab\Payment\Policies\SettlementPolicy;

class PaymentServiceProvider extends \Illuminate\Support\ServiceProvider
{
    public function register()
    {
        $this->app->register(EventServiceProvider::class);
        $this->loadRoutesFrom(__DIR__."/../Routes/payment_routes.php");
        $this->loadRoutesFrom(__DIR__."/../Routes/settlement_routes.php");
        $this->loadMigrationsFrom(__DIR__."/../Database/Migrations/");
        $this->loadViewsFrom(__DIR__.'/../Resources/Views/','Payment');
        $this->loadJsonTranslationsFrom(__DIR__.'/../Resources/Lang/');
//        DatabaseSeeder::$Seeders[] = PaymentSeeder::class;
        Gate::policy(Payment::class,PaymentPolicy::class);
        Gate::policy(Payment::class,SettlementPolicy::class);

    }

    public function boot(){
        $this->app->singleton(Gateway::class,function (){
            return new NextpayAdaptor();
        });
        $this->app->booted(function (){
            config()->set("AdminSidebar.transactions",[
                "name" => "مدیریت پرداخت ها",
                "link" => route("payment.index"),
                "icon" => "fa-credit-card",
                "children"=>[
                    ["name"=>" لیست پرداخت های خدمات","link"=>route("payment.index")],
                    ["name"=>" تراکنش های فروشگاه","link"=>route("admin_transaction_list")],
                    ["name"=>" تراکنش های کیف پول","link"=>route("admin_wallet_transactions")],
                    ["name"=>"آمار پرداخت ها","link"=>route("payment.info")],
                    ["name"=>"لیست تسویه","link"=>route("settlement.index")],

                ],
                "permission"=>\Mehrab\RolePermission\Models\Permission::PERMISSION_MANAGE_PAYMENT
            ]);
        });

        $this->app->booted(function (){
            config()->set("AdminSidebar.settlement",[
                "name" => "درخواست تسویه",
                "link" => route("payment.index"),
                "icon" => "fa-credit-card",
                "children"=>[
                     ["name"=>" درخواست تسویه","link"=>route("settlement.create")],

                ],
                "permission"=>\Mehrab\RolePermission\Models\Permission::PERMISSION_EXPERT
            ]);
        });

    }
}
