<?php

namespace Mamad\Product\Providers;

use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Mamad\Brand\Models\Brand;
use Mamad\Category\Models\Category;
use Mamad\Product\Models\Product;
use Mamad\Product\policies\ProductPolicy;

class ProductServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->loadViewsFrom(__DIR__."/../Resources/Views/","Product");
        $this->loadMigrationsFrom(__DIR__."/../Database/Migrations");

    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        $this->loadRoutesFrom(__DIR__."/../routes/product_route.php");
        $this->loadRoutesFrom(__DIR__."/../routes/coupon_route.php");

        if(Schema::hasTable('products')) {
            config()->set("MenuItem.items.محصولات", ["items" => Product::get(), "type" => "product"]);
            Gate::policy(Product::class,ProductPolicy::class);
        }

        Category::$post_type[]="product";
        Brand::$post_type[]="product";

        $this->app->booted(function (){
            config()->set("AdminSidebar.product",[
                "name" => "محصولات",
                "link" => route("admin_product_list"),
                "icon" => "fa-shopping-basket",
                "children"=>[
                    ["name"=>"لیست محصولات تکی","link"=>route("admin_product_list")],
                    ["name"=>"افزودن محصول تکی","link"=>route("admin_product_add")],
                    ["name"=>"برند های محصولات تکی","link"=>route("admin_add_brand",['post_type' => 'product']) ],
                    ["name"=>" دسته بندی محصولات تکی","link"=>route("admin_add_category",['post_type' => 'product'])],
                    ["name"=>"لیست زیر محصولات گروهی","link"=>route("children_group_product.list")],
                    ["name"=>"افزودن زیر محصول گروهی","link"=>route("children_group_product.add")],
                    ["name"=>"لیست محصولات گروهی","link"=>route("group_product.list")],
                    ["name"=>"افزودن محصول گروهی","link"=>route("group_product.add")],
                    ["name"=>" دسته بندی محصولات گروهی","link"=>route("admin_add_category",['post_type' => 'group_product'])],
                    ["name"=>"برند های محصولات گروهی","link"=>route("admin_add_brand",['post_type' => 'group_product']) ],
                    ["name"=>"ویژگی ها","link"=>route("admin_add_attribute",['post_type' => 'product']) ],
                    //["name"=>"قایل اکسل قیمت محصولات","link"=>route("admin_product_excel") ],
                ],
                "permission"=>\Mamad\RolePermissions\Models\Permission::PERMISSION_PRODUCT_MANAGER
            ]);
        });

    }
}
