<?xml version="1.0"?>
<!--
/**
 * @author 1902 Software
 * @copyright Copyright © 2023 1902 Software (https://1902software.com/magento/)
 * @package WriteTextAI_WriteTextAI
 */
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
	<preference for="WriteTextAI\WriteTextAI\Api\AiProductRepositoryInterface" type="WriteTextAI\WriteTextAI\Model\AiProductRepository"/>
    <preference for="WriteTextAI\WriteTextAI\Api\Data\AiProductInterface" type="WriteTextAI\WriteTextAI\Model\AiProduct"/>
    <preference for="WriteTextAI\WriteTextAI\Api\Data\AiProductSearchResultsInterface" type="Magento\Framework\Api\SearchResults" />

	<preference for="WriteTextAI\WriteTextAI\Api\UserFieldsSelectedRepositoryInterface" type="WriteTextAI\WriteTextAI\Model\UserFieldsSelectedRepository"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\UserFieldsSelectedInterface" type="WriteTextAI\WriteTextAI\Model\UserFieldsSelected"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\UserFieldsSelectedSearchResultsInterface" type="Magento\Framework\Api\SearchResults"/>

    <preference for="WriteTextAI\WriteTextAI\Api\UserWebTokenRepositoryInterface" type="WriteTextAI\WriteTextAI\Model\UserWebTokenRepository"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\UserWebTokenInterface" type="WriteTextAI\WriteTextAI\Model\UserWebToken"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\UserWebTokenSearchResultsInterface" type="Magento\Framework\Api\SearchResults"/>

    <preference for="WriteTextAI\WriteTextAI\Api\SettingRepositoryInterface" type="WriteTextAI\WriteTextAI\Model\SettingRepository"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\SettingInterface" type="WriteTextAI\WriteTextAI\Model\Setting"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\SettingSearchResultsInterface" type="Magento\Framework\Api\SearchResults"/>

	<preference for="WriteTextAI\WriteTextAI\Api\BulkGenerateRequestsRepositoryInterface" type="WriteTextAI\WriteTextAI\Model\BulkGenerateRequestsRepository"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\BulkGenerateRequestsInterface" type="WriteTextAI\WriteTextAI\Model\BulkGenerateRequests"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\BulkGenerateRequestsSearchResultsInterface" type="Magento\Framework\Api\SearchResults"/>

    <preference for="WriteTextAI\WriteTextAI\Api\BulkTransferRequestsRepositoryInterface" type="WriteTextAI\WriteTextAI\Model\BulkTransferRequestsRepository"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\BulkTransferRequestsInterface" type="WriteTextAI\WriteTextAI\Model\BulkTransferRequests"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\BulkTransferRequestsSearchResultsInterface" type="Magento\Framework\Api\SearchResults"/>

    <preference for="WriteTextAI\WriteTextAI\Api\BulkKeywordAnalysisRequestsRepositoryInterface" type="WriteTextAI\WriteTextAI\Model\BulkKeywordAnalysisRequestsRepository"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\BulkKeywordAnalysisRequestsInterface" type="WriteTextAI\WriteTextAI\Model\BulkKeywordAnalysisRequests"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\BulkKeywordAnalysisRequestsSearchResultsInterface" type="Magento\Framework\Api\SearchResults"/>

    <preference for="WriteTextAI\WriteTextAI\Api\AiCategoryRepositoryInterface" type="WriteTextAI\WriteTextAI\Model\AiCategoryRepository"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\AiCategoryInterface" type="WriteTextAI\WriteTextAI\Model\AiCategory"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\AiCategorySearchResultsInterface" type="Magento\Framework\Api\SearchResults"/>

    <preference for="WriteTextAI\WriteTextAI\Api\UserFeedbackRepositoryInterface" type="WriteTextAI\WriteTextAI\Model\UserFeedbackRepository"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\UserFeedbackInterface" type="WriteTextAI\WriteTextAI\Model\UserFeedback"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\UserFeedbackSearchResultsInterface" type="Magento\Framework\Api\SearchResults"/>

    <preference for="WriteTextAI\WriteTextAI\Api\SingleGenerateRequestsRepositoryInterface" type="WriteTextAI\WriteTextAI\Model\SingleGenerateRequestsRepository"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\SingleGenerateRequestsInterface" type="WriteTextAI\WriteTextAI\Model\SingleGenerateRequests"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\SingleGenerateRequestsSearchResultsInterface" type="Magento\Framework\Api\SearchResults"/>
    
	<preference for="WriteTextAI\WriteTextAI\Api\NewRecordsRepositoryInterface" type="WriteTextAI\WriteTextAI\Model\NewRecordsRepository"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\NewRecordsInterface" type="WriteTextAI\WriteTextAI\Model\NewRecords"/>
	<preference for="WriteTextAI\WriteTextAI\Api\Data\NewRecordsSearchResultsInterface" type="Magento\Framework\Api\SearchResults"/>
    
    <preference for="Magento\Framework\Api\Search\SearchCriteriaBuilder" type="WriteTextAI\WriteTextAI\Model\SearchCriteriaBuilder"/>

    <type name="WriteTextAI\WriteTextAI\Logger\Handler">
        <arguments>
            <argument name="filesystem" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
        </arguments>
    </type>
    <type name="WriteTextAI\WriteTextAI\Logger\Logger">
        <arguments>
            <argument name="name" xsi:type="string">apiLogger</argument>
            <argument name="handlers"  xsi:type="array">
                <item name="system" xsi:type="object">WriteTextAI\WriteTextAI\Logger\Handler</item>
            </argument>
        </arguments>
    </type>
    <type name="WriteTextAI\WriteTextAI\Logger\CronLogger">
        <arguments>
            <argument name="name" xsi:type="string">cronLogger</argument>
            <argument name="handlers"  xsi:type="array">
                <item name="system" xsi:type="object">WriteTextAI\WriteTextAI\Logger\CronHandler</item>
            </argument>
        </arguments>
    </type>

    <type name="WriteTextAI\WriteTextAI\Ui\DataProvider\Products\ListingDataProvider">
        <plugin name="wtai_products_attributes" type="WriteTextAI\WriteTextAI\Plugin\AddAttributesToUiDataProvider" />
    </type>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="wtai_products_grid_listing_data_source" xsi:type="string">wtaiProductsGridCollection</item>
            </argument>
        </arguments>
    </type>
    <virtualType name="wtaiProductsGridCollection" type="WriteTextAI\WriteTextAI\Ui\DataProvider\Products\Listing\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">catalog_product_entity</argument>
            <argument name="resourceModel" xsi:type="string">WriteTextAI\WriteTextAI\Model\ResourceModel\Product</argument>
        </arguments>
    </virtualType>
    
    <type name="Magento\Ui\Component\MassAction">
        <plugin name="wtai_mass_action_bulk_generate_settings" type="WriteTextAI\WriteTextAI\Plugin\Component\MassAction" />
    </type>

    <type name="WriteTextAI\WriteTextAI\Controller\Adminhtml\Edit\Index">
        <arguments>
            <argument name="directivePatterns" xsi:type="array">
                <item name="construct" xsi:type="const">\Magento\Framework\Filter\Template::CONSTRUCTION_PATTERN</item>
            </argument>
        </arguments>
    </type>

    <type name="Magento\Ui\Component\Listing\Columns\Column">
        <plugin name="wtai_products_grid_listing_column_plugin" type="WriteTextAI\WriteTextAI\Plugin\Component\Listing\Columns\Column" />
    </type>

    <type name="Magento\Framework\Console\CommandList">
		<arguments>
			<argument name="commands" xsi:type="array">
				<item name="LocationsImport" xsi:type="object">WriteTextAI\WriteTextAI\Console\Command\LocationsImport</item>
				<item name="ResetData" xsi:type="object">WriteTextAI\WriteTextAI\Console\Command\ResetData</item>
				<item name="ReuploadThumbnails" xsi:type="object">WriteTextAI\WriteTextAI\Console\Command\ReuploadThumbnails</item>
			</argument>
		</arguments>
	</type>
    <type name="WriteTextAI\WriteTextAI\Console\Command\LocationsImport">
		<arguments>
			<argument name="settingsManager" xsi:type="object">WriteTextAI\WriteTextAI\Model\SettingManager\Proxy</argument>
			<argument name="appState" xsi:type="object">Magento\Framework\App\State\Proxy</argument>
			<argument name="dataHelper" xsi:type="object">WriteTextAI\WriteTextAI\Helper\Data\Proxy</argument>
		</arguments>
	</type>
    <type name="WriteTextAI\WriteTextAI\Console\Command\ResetData">
		<arguments>
			<argument name="resource" xsi:type="object">Magento\Framework\App\ResourceConnection\Proxy</argument>
		</arguments>
	</type>
    <type name="WriteTextAI\WriteTextAI\Console\Command\ReuploadThumbnails">
		<arguments>
			<argument name="appState" xsi:type="object">Magento\Framework\App\State\Proxy</argument>
			<argument name="reuploadThumbnailsModel" xsi:type="object">WriteTextAI\WriteTextAI\Model\Keywords\ReuploadThumbnails\Proxy</argument>
		</arguments>
	</type>
    <type name="WriteTextAI\WriteTextAI\Observer\Catalog\ProductSaveAfter">
        <arguments>
            <argument name="newRecordsManager" xsi:type="object">WriteTextAI\WriteTextAI\Model\NewRecordsManager\Proxy</argument>
        </arguments>
    </type>
    <type name="WriteTextAI\WriteTextAI\Observer\Catalog\ProductImportBunchSaveAfter">
        <arguments>
            <argument name="newRecordsManager" xsi:type="object">WriteTextAI\WriteTextAI\Model\NewRecordsManager\Proxy</argument>
        </arguments>
    </type>

    <!-- API Interface Preferences -->
    <preference for="WriteTextAI\WriteTextAI\Api\RecordManagementInterface"
                type="WriteTextAI\WriteTextAI\Model\RecordManagement" />
    <preference for="WriteTextAI\WriteTextAI\Api\PingInterface"
                type="WriteTextAI\WriteTextAI\Model\Ping" />
    <preference for="WriteTextAI\WriteTextAI\Api\Data\PingResultInterface"
                type="WriteTextAI\WriteTextAI\Model\Data\PingResult" />
    <preference for="WriteTextAI\WriteTextAI\Api\ImageApiInterface"
                type="WriteTextAI\WriteTextAI\Model\ImageApi" />
    <preference for="WriteTextAI\WriteTextAI\Api\ImageBase64ApiInterface"
                type="WriteTextAI\WriteTextAI\Model\ImageBase64Api" />
    <preference for="WriteTextAI\WriteTextAI\Api\RecordDetailsApiInterface"
                type="WriteTextAI\WriteTextAI\Model\RecordDetailsApi" />

    <!-- Categories -->
    <type name="WriteTextAI\WriteTextAI\Ui\DataProvider\Categories\ListingDataProvider">
        <plugin name="wtai_categories_attributes" type="WriteTextAI\WriteTextAI\Plugin\Categories\AddAttributesToUiDataProvider" />
    </type>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="wtai_categories_grid_listing_data_source" xsi:type="string">wtaiCategoriesGridCollection</item>
            </argument>
        </arguments>
    </type>
    <virtualType name="wtaiCategoriesGridCollection" type="WriteTextAI\WriteTextAI\Ui\DataProvider\Categories\Listing\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">catalog_category_entity</argument>
            <argument name="resourceModel" xsi:type="string">WriteTextAI\WriteTextAI\Model\ResourceModel\Category</argument>
        </arguments>
    </virtualType>
    <!-- End Categories -->

    <type name="Magento\Framework\App\Action\Action">
        <plugin name="wtai_total_credits_plugin" type="WriteTextAI\WriteTextAI\Plugin\TotalCreditsPlugin" />
    </type>
</config>