<?php
/**
 * 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_SeoRule
 * @copyright   Copyright (c) Mageplaza (http://www.mageplaza.com/)
 */

namespace Mageplaza\SeoRule\Model\ResourceModel\Meta;

use Magento\Framework\DB\Select;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Mageplaza\SeoRule\Model\Meta;
use Mageplaza\SeoRule\Model\ResourceModel\Meta as MetaResourceModel;
use Zend_Db_Select;

/**
 * Class Collection
 * @package Mageplaza\SeoRule\Model\ResourceModel\Meta
 */
class Collection extends AbstractCollection
{
    /**
     * @var string
     */
    protected $_idFieldName = 'meta_id';

    /**
     * @var string
     */
    protected $_eventPrefix = 'mageplaza_seorule_meta_collection';

    /**
     * @var string
     */
    protected $_eventObject = 'meta_collection';

    /**
     * Define resource model
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_init(Meta::class, MetaResourceModel::class);
    }

    /**
     * Get SQL for get record count.
     * Extra GROUP BY strip added.
     *
     * @return Select
     */
    public function getSelectCountSql()
    {
        $countSelect = parent::getSelectCountSql();
        $countSelect->reset(Zend_Db_Select::GROUP);

        return $countSelect;
    }

    /**
     * @param string $valueField
     * @param string $labelField
     * @param array $additional
     *
     * @return array
     */
    protected function _toOptionArray($valueField = null, $labelField = 'name', $additional = [])
    {
        $valueField = 'meta_id';
        $labelField = 'meta_title';

        return parent::_toOptionArray($valueField, $labelField, $additional);
    }
}
