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

class AllowedCountries implements \Magento\Framework\Option\ArrayInterface
{
    const BRANDED_UNBRANDED_COUNTRIES = [
        'AU',
        'BE',
        'BG',
        'CY',
        'CZ',
        'DK',
        'EE',
        'FI',
        'FR',
        'GR',
        'HU',
        'IT',
        'LV',
        'LI',
        'LT',
        'LU',
        'MT',
        'NL',
        'NO',
        'PL',
        'PT',
        'RO',
        'SK',
        'SI',
        'ES',
        'SE',
        'GB',
        'US'
    ];

    const BRANDED_COUNTRIES = [
        'AT',
        'CA',
        'DE',
        'IE',
    ];

    /**
     * @param \Magento\Directory\Model\Config\Source\Country $countryCollection
     */
    public function __construct(\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollection)
    {
        $this->_countryCollection = $countryCollection;
    }

    /**
     * Possible allowed countries.
     *
     * @return array
     */
    public function toOptionArray($isMultiselect = true)
    {
        $allowedCountries = array_merge(self::BRANDED_UNBRANDED_COUNTRIES, self::BRANDED_COUNTRIES);

        $countryList = $this->_countryCollection->create()->addCountryCodeFilter($allowedCountries);
        
        $options = $countryList->toOptionArray(
            false
        );
        if (!$isMultiselect) {
            array_unshift($options, ['value' => '', 'label' => __('--Please Select--')]);
        }

        return $options;
    }
}
