<?xml version="1.0"?>
<!--
/**
 * Mageplaza
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Mageplaza.com license that is
 * available through the world-wide-web at this URL:
 * https://www.mageplaza.com/LICENSE.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category    Mageplaza
 * @package     Mageplaza_AdminPermissions
 * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
 * @license     https://www.mageplaza.com/LICENSE.txt
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!--  LIMIT FOR ROLE  -->
    <type name="Magento\User\Block\Role">
        <plugin name="mp_ap_limit_check_add_new_role_button" type="Mageplaza\AdminPermissions\Plugin\User\Block\Role"/>
    </type>
    <type name="Magento\User\Block\Buttons">
        <plugin name="mp_ap_limit_check_edit_role_button" type="Mageplaza\AdminPermissions\Plugin\User\Block\Buttons"/>
    </type>
    <type name="Magento\Authorization\Model\ResourceModel\Role\Grid\Collection">
        <plugin name="mp_ap_limit_role_collection" type="Mageplaza\AdminPermissions\Plugin\Authorization\Model\ResourceModel\Role\Grid\Collection"/>
    </type>

    <!--  Remove resource when disabled module  -->
    <type name="Magento\Integration\Helper\Data">
        <plugin name="mp_ap_limit_disable_ap_resource" type="Mageplaza\AdminPermissions\Plugin\Integration\Helper\Data"/>
    </type>

    <!--  LIMIT FOR SALES  -->
    <!--    Limit for sale items (hide row in grid)-->
    <type name="Magento\Sales\Model\ResourceModel\Order\Grid\Collection">
        <plugin name="mp_sales_order_collection_limit_access" type="Mageplaza\AdminPermissions\Plugin\Sales\Model\ResourceModel\Order\Grid\Collection"/>
    </type>
    <type name="Magento\Sales\Model\ResourceModel\Order\Collection">
        <plugin name="mp_sales_order_collection_api_limit_access" type="Mageplaza\AdminPermissions\Plugin\Sales\Model\ResourceModel\Order\Collection"/>
    </type>
    <type name="Magento\Sales\Model\ResourceModel\Order\Invoice\Grid\Collection">
        <plugin name="mp_sales_order_invoice_collection_limit_access" type="Mageplaza\AdminPermissions\Plugin\Sales\Model\ResourceModel\Order\Invoice\Grid\Collection"/>
    </type>
    <type name="Magento\Sales\Model\ResourceModel\Order\Shipment\Grid\Collection">
        <plugin name="mp_sales_order_shipment_collection_limit_access" type="Mageplaza\AdminPermissions\Plugin\Sales\Model\ResourceModel\Order\Shipment\Grid\Collection"/>
    </type>
    <type name="Magento\Sales\Model\ResourceModel\Order\Creditmemo\Grid\Collection">
        <plugin name="mp_sales_order_creditmemo_collection_limit_access" type="Mageplaza\AdminPermissions\Plugin\Sales\Model\ResourceModel\Order\Creditmemo\Grid\Collection"/>
    </type>
    <type name="Magento\Sales\Model\ResourceModel\Transaction\Grid\Collection">
        <plugin name="mp_sales_order_creditmemo_collection_limit_access" type="Mageplaza\AdminPermissions\Plugin\Sales\Model\ResourceModel\Transaction\Grid\Collection"/>
    </type>
    <type name="Magento\Wishlist\Model\ResourceModel\Item\Collection\Grid">
        <plugin name="mp_ap_limit_customer_collection_when_create_order" type="Mageplaza\AdminPermissions\Plugin\Wishlist\Model\ResourceModel\Item\Collection\Grid"/>
    </type>

    <!--    Limit store when create order (hide limited selection) -->
    <type name="Magento\Sales\Block\Adminhtml\Order\Create\Store\Select">
        <plugin name="mp_ap_limit_create_new_order_by_store" type="Mageplaza\AdminPermissions\Plugin\Sales\Block\Adminhtml\Order\Create\Store\Select"/>
    </type>

    <!--  LIMIT FOR CATEGORY  -->
    <!--    Hide category in tree  -->
    <type name="Magento\Catalog\Block\Adminhtml\Category\Tree">
        <plugin name="mp_ap_limit_view_category_tree" type="Mageplaza\AdminPermissions\Plugin\Catalog\Block\Adminhtml\Category\Tree"/>
    </type>

    <!--  LIMIT FOR PRODUCT  -->
    <!--    Show permission error when create new attribute in product page-->
    <type name="Magento\Catalog\Controller\Adminhtml\Product\Attribute\Validate">
        <plugin name="mp_ap_limit_create_new_product_attribute" type="Mageplaza\AdminPermissions\Plugin\Catalog\Controller\Adminhtml\Product\Attribute\Validate"/>
    </type>
    <!--    Show permission error when mass delete product-->
    <type name="Magento\Catalog\Controller\Adminhtml\Product\MassDelete">
        <plugin name="mp_ap_limit_create_new_product_attribute" type="Mageplaza\AdminPermissions\Plugin\Catalog\Controller\Adminhtml\Product\MassDelete"/>
    </type>
    <type name="Magento\Sales\Model\ResourceModel\Order\Customer\Collection">
        <plugin name="mp_ap_limit_product_in_wishlist" type="Mageplaza\AdminPermissions\Plugin\Sales\Model\ResourceModel\Order\Customer\Collection"/>
    </type>
    <type name="Magento\Catalog\Block\Adminhtml\Product">
        <plugin name="mp_ap_check_create_new_product_button" type="Mageplaza\AdminPermissions\Plugin\Catalog\Block\Adminhtml\Product"/>
    </type>
    <type name="Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Button\Save">
        <plugin name="mp_ap_check_save_product_button" type="Mageplaza\AdminPermissions\Plugin\ConfigurableProduct\Block\Adminhtml\Product\Edit\Button\Save"/>
    </type>
    <type name="Magento\Catalog\Model\ResourceModel\Product\Collection">
        <plugin name="mp_ap_limit_product_collection" type="Mageplaza\AdminPermissions\Plugin\Catalog\Model\ResourceModel\Product\Collection"/>
    </type>
    <type name="Magento\CatalogInventory\Model\Stock\StockItemRepository">
        <plugin name="mp_ap_limit_product_save" type="Mageplaza\AdminPermissions\Plugin\Catalog\Model\Stock\StockItemRepository"/>
    </type>

    <!--  LIMIT FOR CUSTOMER  -->
    <type name="Magento\Customer\Model\ResourceModel\Grid\Collection">
        <plugin name="mp_ap_limit_customer_collection" type="Mageplaza\AdminPermissions\Plugin\Customer\Model\ResourceModel\Grid\Collection"/>
    </type>
    <type name="Magento\Customer\Block\Adminhtml\Edit">
        <plugin name="mp_ap_limit_check_customer_button" type="Mageplaza\AdminPermissions\Plugin\Customer\Block\Adminhtml\Edit"/>
    </type>

    <!--  LIMIT FOR PRODUCT ATTRIBUTE  -->
    <type name="Magento\Catalog\Block\Adminhtml\Product\Attribute">
        <plugin name="mp_ap_limit_check_add_new_product_attribute_button" type="Mageplaza\AdminPermissions\Plugin\Catalog\Block\Adminhtml\Product\Attribute"/>
    </type>
    <type name="Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit">
        <plugin name="mp_ap_limit_check_edit_product_attribute_button" type="Mageplaza\AdminPermissions\Plugin\Catalog\Block\Adminhtml\Product\Attribute\Edit"/>
    </type>
    <type name="Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection">
        <plugin name="mp_ap_limit_product_attribute_collection" type="Mageplaza\AdminPermissions\Plugin\Catalog\Model\ResourceModel\Product\Attribute\Collection"/>
    </type>

    <!--    Add Valid Time Fieldset to Role Info Tab -->
    <type name="Magento\User\Block\Role\Tab\Info">
        <plugin name="mp_ap_valid_time_fieldset" type="Mageplaza\AdminPermissions\Plugin\User\Block\Role\Tab\Info"/>
    </type>

    <type name="Magento\Catalog\Model\ResourceModel\Category\Collection">
        <plugin name="mp_ap_valid_category_in_collection" type="Mageplaza\AdminPermissions\Plugin\Catalog\Model\ResourceModel\Category\Collection"/>
    </type>
    <type name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Categories">
        <plugin name="mp_ap_valid_category_in_collection_2" type="Mageplaza\AdminPermissions\Plugin\Catalog\Ui\DataProvider\Product\Form\Modifier\LimitCategory"/>
    </type>
</config>
