<?php

namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Action\Cron;

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Config\Config;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Service\Listener\Items\Hookable\Hookable;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Infrastructure\Request\Request;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Action\Process\ExportProcessAction;
class ExportCronAction implements Hookable
{
    const CRON_ACTION = 'dropshipping_export_process';
    private ExportProcessAction $export_process;
    public function __construct(ExportProcessAction $import_process)
    {
        $this->export_process = $import_process;
    }
    public function hooks()
    {
        add_filter('cron_schedules', [$this, 'cron_schedules']);
        //phpcs:ignore
        add_action('init', [$this, 'register_cron']);
        add_action(self::CRON_ACTION, [$this->export_process, 'process']);
    }
    public function register_cron()
    {
        if (!wp_next_scheduled(self::CRON_ACTION)) {
            wp_schedule_event(time(), 'every_minute', self::CRON_ACTION);
        }
    }
    public function cron_schedules($schedules): array
    {
        $schedules['every_minute'] = ['interval' => 60, 'display' => __('Every minute', 'dropshipping-export-free')];
        return $schedules;
    }
}
