<?php
/**
 * Webkul Software.
 *
 * @category  Webkul
 * @package   Webkul_Agorae
 * @author    Webkul
 * @copyright Copyright (c) Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html
 */
namespace Webkul\Agorae\Model;

use Webkul\Agorae\Api\Data\MpfavouritesellerInterface;
use Webkul\Agorae\Model\ResourceModel\Mpfavouriteseller\Collection;

/**
 * Webkul Agorae MpfavouritesellerRepository Model
 */
class MpfavouritesellerRepository implements \Webkul\Agorae\Api\MpfavouritesellerRepositoryInterface
{
    /**
     * @var MpfavouritesellerRepository
     */
    protected $_mpFavouritesellerFactory;

    /**
     * @var \Webkul\Agorae\Model\ResourceModel\MpFavouriteSeller\CollectionFactory
     */
    protected $_collectionFactory;

    /**
     * @var \Webkul\Agorae\Model\ResourceModel\Mpfavouriteseller
     */
    protected $_resourceModel;

    /**
     * @var \Magento\Framework\Api\ExtensibleDataObjectConverter
     */
    protected $_extensibleDataObjectConverter;

    /**
     * @param MpfavouritesellerFactory                                         $mpFavouritesellerFactory
     * @param \Webkul\Agorae\Model\ResourceModel\Mpfavouriteseller\CollectionFactory $collectionFactory
     * @param \Webkul\Agorae\Model\ResourceModel\Mpfavouriteseller  $resourceModel
     * @param \Magento\Framework\Api\ExtensibleDataObjectConverter             $extensibleDataObjectConverter
     */
    public function __construct(
        MpfavouritesellerFactory $mpFavouritesellerFactory,
        \Webkul\Agorae\Model\ResourceModel\Mpfavouriteseller\CollectionFactory $collectionFactory,
        \Webkul\Agorae\Model\ResourceModel\Mpfavouriteseller $resourceModel,
        \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter
    ) {
        $this->_resourceModel = $resourceModel;
        $this->_mpFavouritesellerFactory = $mpFavouritesellerFactory;
        $this->_collectionFactory = $collectionFactory;
        $this->_extensibleDataObjectConverter = $extensibleDataObjectConverter;
    }

    /**
     * Get seller collection by customer id
     *
     * @param  int $sellerId   contain seller id
     * @param  id $customerId contain customer id
     * @return object
     */
    public function getSellerCollectionByCustomerId($sellerId, $customerId)
    {
        $sellerCollection = $this->_mpFavouritesellerFactory->create()->getCollection()
        ->addFieldToFilter(
            'seller_id',
            [
                'eq'=>$sellerId
            ]
        )
        ->addFieldToFilter(
            'customer_id',
            [
                'eq'=>$customerId
            ]
        );
        return $sellerCollection;
    }

    /**
     * Get all seller collection by seller id
     *
     * @param  int $customerId contain customer id
     * @return object
     */
    public function getsellersCollectionByCustomerId($customerId)
    {
        $sellersCollection = $this->_mpFavouritesellerFactory->create()->getCollection()
        ->addFieldToFilter(
            'customer_id',
            [
                'eq'=>$customerId
            ]
        );
        return $sellersCollection;
    }

    /**
     * Get all customers of a seller
     *
     * @param  int $sellerId contain seller id
     * @return object
     */
    public function getCustomersCollectionBySellerId($sellerId)
    {
        $sellersCollection = $this->_mpFavouritesellerFactory->create()->getCollection()
        ->addFieldToFilter(
            'seller_id',
            [
                'eq'=>$sellerId
            ]
        );
        return $sellersCollection;
    }
}
