<?php
/**
 * @copyright   Copyright (c) 2023 TheMarketer.com
 * @project     TheMarketer.com
 * @website     https://themarketer.com/
 * @author      TheMarketer
 * @license     http://opensource.org/licenses/osl-3.0.php - Open Software License (OSL 3.0)
 * @docs        https://themarketer.com/resources/api
 */

namespace Mktr\Tracker\Controller\Api;

use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Newsletter\Model\Subscriber;
use Mktr\Tracker\Helper\Data;

class Feed implements HttpGetActionInterface
{
    /**
     * @var Data
     */
    private $helper;

    private $fileName = "products";
    private $secondName = "product";

    public function __construct(Data $helper)
    {
        $this->helper = $helper;
    }

    public function execute()
    {
        $error = $this->helper->getFunc->isParamValid([
            'key' => 'KeyAuth'
        ]);

        if ($error === null) {
            return $this->helper->getFunc->readOrWrite($this->fileName, $this->secondName, $this);
        }

        return $this->helper->getFunc->Output('status', $error);
    }

    public function freshData(): array
    {
        return $this->helper->getPagesFeed->freshData();
    }
}
