<?php
/**
 * @author 1902 Software
 * @copyright Copyright © 2023 1902 Software (https://1902software.com/magento/)
 * @package WriteTextAI_WriteTextAI
 */

namespace WriteTextAI\WriteTextAI\Model\Config\Source;

use Magento\Framework\Data\OptionSourceInterface;
use WriteTextAI\WriteTextAI\Model\SettingManager;
use WriteTextAI\WriteTextAI\Model\Api\Session as ApiSession;

class Styles implements OptionSourceInterface
{
    /**
     * @var SettingManager
     */
    protected $settingManager;

    /**
     * @var ApiSession
     */
    protected $apiSession;

    /**
     * Constructor
     *
     * @param SettingManager $settingManager
     * @param ApiSession $apiSession
     */
    public function __construct(
        SettingManager $settingManager,
        ApiSession $apiSession
    ) {
        $this->settingManager = $settingManager;
        $this->apiSession = $apiSession;
    }

    /**
     * Get options
     *
     * @return array
     */
    public function toOptionArray()
    {
        $language = $this->apiSession->getRegionIndependentLanguage();
        $styles = $this->settingManager->getSettings('styles', $language);
        
        $options = [];
        
        foreach ($styles as $style) {
            $options[] = [
                'value' => $style['id'],
                'label' => $style['name']
            ];
        }
        
        return $options;
    }
}
