<?php

namespace App\Providers;

use App\Models\CMS\Forms\ContactUS;
use App\Models\CMS\Marketing\Newsletter;
use App\Models\CMS\Marketing\NewsletterUser;
use App\Models\CMS\Media\Banner;
use App\Models\CMS\Media\Carousel;
use App\Models\CMS\Media\Gallery;
use App\Models\Ecommerce\Channel\Channel;
use App\Models\Ecommerce\Payouts\Payout;
use App\Models\Ecommerce\Product\Brand\Brand;
use App\Models\Ecommerce\Product\Category\Category;
use App\Models\Ecommerce\Product\Collection\Collection;
use App\Models\Ecommerce\Product\Coupon\Coupon;
use App\Models\Ecommerce\Product\Inventory\Inventory;
use App\Models\Ecommerce\Product\Order\Order;
use App\Models\Ecommerce\Product\Order\OrderItem;
use App\Models\Ecommerce\Product\Product\Product;
use App\Models\Ecommerce\Product\Property\Attribute;
use App\Models\Ecommerce\Product\Review\Review;
use App\Models\Legal\LegalPage;
use App\Models\Post\PostBranch;
use App\Models\System\Roles\Permission;
use App\Models\System\Roles\Role;
use App\Models\System\Settings\Location\Province;
use App\Models\System\Settings\Payments\PaymentType;
use App\Models\System\VersionManagement\AppVersion;
use App\Models\User;
use App\Policies\CMS\Forms\ContactUSPolicy;
use App\Policies\CMS\Marketing\NewsletterPolicy;
use App\Policies\CMS\Marketing\NewsletterUserPolicy;
use App\Policies\CMS\Media\BannerPolicy;
use App\Policies\CMS\Media\CarouselPolicy;
use App\Policies\CMS\Media\GalleryPolicy;
use App\Policies\Ecommerce\Channel\ChannelPolicy;
use App\Policies\Ecommerce\Payout\PayoutPolicy;
use App\Policies\Ecommerce\Product\Brand\BrandPolicy;
use App\Policies\Ecommerce\Product\Category\CategoryPolicy;
use App\Policies\Ecommerce\Product\Collection\CollectionPolicy;
use App\Policies\Ecommerce\Product\Coupon\CouponPolicy;
use App\Policies\Ecommerce\Product\Inventory\InventoryPolicy;
use App\Policies\Ecommerce\Product\Order\OrderItemPolicy;
use App\Policies\Ecommerce\Product\Order\OrderPolicy;
use App\Policies\Ecommerce\Product\Product\ProductPolicy;
use App\Policies\Ecommerce\Product\Property\AttributePolicy;
use App\Policies\Ecommerce\Product\Review\ReviewPolicy;
use App\Policies\Legal\LegalPagePolicy;
use App\Policies\Post\PostBranchPolicy;
use App\Policies\System\Roles\PermissionPolicy;
use App\Policies\System\Roles\RolePolicy;
use App\Policies\System\Settings\Location\ProvincePolicy;
use App\Policies\System\Settings\Payments\PaymentTypePolicy;
use App\Policies\System\VersionManagement\AppVersionPolicy;
use App\Policies\UserPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The model to policy mappings for the application.
     *
     * @var array<class-string, class-string>
     */
    protected $policies = [
        // Orders...
        Order::class => OrderPolicy::class,
        OrderItem::class => OrderItemPolicy::class,

        // Products...
        Product::class => ProductPolicy::class,
        Coupon::class => CouponPolicy::class,
        Review::class => ReviewPolicy::class,

        // Product Attributes...
        Attribute::class => AttributePolicy::class,

        // Inventories...
        Inventory::class => InventoryPolicy::class,

        // Channels...
        Channel::class => ChannelPolicy::class,

        // Collectons...
        Collection::class => CollectionPolicy::class,

        // Categories...
        Category::class => CategoryPolicy::class,

        // Brands...
        Brand::class => BrandPolicy::class,

        // Users...
        User::class => UserPolicy::class,

        // Carousels...
        Carousel::class => CarouselPolicy::class,

        Payout::class => PayoutPolicy::class,

        // CMS...
        Gallery::class => GalleryPolicy::class,
        LegalPage::class => LegalPagePolicy::class,
        ContactUS::class => ContactUSPolicy::class,

        // Marketing...
        Newsletter::class => NewsletterPolicy::class,
        NewsletterUser::class => NewsletterUserPolicy::class,

        // Banners...
        Banner::class => BannerPolicy::class,

        // Permissions (settings)...
        Role::class => RolePolicy::class,
        Permission::class => PermissionPolicy::class,

        // Location (settings)...
        Province::class => ProvincePolicy::class,
        PostBranch::class => PostBranchPolicy::class,

        // App settings...
        AppVersion::class => AppVersionPolicy::class,

        // Order settings...
        PaymentType::class => PaymentTypePolicy::class,
    ];

    /**
     * Register any authentication / authorization services.
     */
    public function boot(): void
    {
        Gate::define('isMe', fn ($user) => $user->isMe());
        Gate::define('isAdmin', fn ($user) => $user->isAdmin());
        Gate::define('systemUser', fn ($user) => $user->isMe() || $user->hasRole(['admin', 'manager']));
        Gate::define('vendor', fn ($user) => $user->hasRole('vendor'));
        Gate::define('isVendor', fn ($user) => $user->hasRole('vendor'));
    }
}
