<?php

namespace iwbvel\classes\services\background_process;

defined('ABSPATH') || exit(); // Exit if accessed directly

use iwbvel\classes\services\background_process\BackgroundProcess;
use iwbvel\classes\repositories\Setting;
use iwbvel\classes\services\background_process\handlers\HistoryRedoHandler;
use iwbvel\classes\services\background_process\handlers\HistoryUndoHandler;
use iwbvel\classes\services\background_process\handlers\ProductCreateHandler;
use iwbvel\classes\services\background_process\handlers\ProductDeleteHandler;
use iwbvel\classes\services\background_process\handlers\ProductDuplicateHandler;
use iwbvel\classes\services\background_process\handlers\ProductRestoreHandler;
use iwbvel\classes\services\background_process\handlers\ProductUpdateHandler;
use iwbvel\classes\services\background_process\handlers\VariationAddHandler;
use iwbvel\classes\services\background_process\handlers\VariationAttachHandler;
use iwbvel\classes\services\background_process\handlers\VariationDeleteHandler;
use iwbvel\classes\services\background_process\handlers\VariationReplaceHandler;
use iwbvel\classes\services\background_process\handlers\VariationSwapHandler;

class VariationBackgroundProcess extends BackgroundProcess
{
    private static $instance;
    private static $is_enable;

    protected $prefix = 'iwbvel';

    public static function init()
    {
        if (is_null(self::$instance)) {
            self::$instance = new self();
        }

        $setting_repository = Setting::get_instance();
        $settings = $setting_repository->get_settings();
        self::$is_enable = (!empty($settings['enable_background_processing']) && $settings['enable_background_processing'] == 'no') ? false : true;
    }

    public function __construct()
    {
        parent::__construct();
    }

    public static function get_instance()
    {
        return self::$instance;
    }

    public static function is_enable()
    {
        return (!defined('IWBVE_ACTIVE') || !IWBVE_ACTIVE) ? false : self::$is_enable;
    }

    protected function get_handlers()
    {
        return [
            'product_update' => ProductUpdateHandler::class,
            'product_create' => ProductCreateHandler::class,
            'product_delete' => ProductDeleteHandler::class,
            'product_restore' => ProductRestoreHandler::class,
            'product_duplicate' => ProductDuplicateHandler::class,
            'history_undo' => HistoryUndoHandler::class,
            'history_redo' => HistoryRedoHandler::class,
            'variation_add' => VariationAddHandler::class,
            'variation_replace' => VariationReplaceHandler::class,
            'variation_delete' => VariationDeleteHandler::class,
            'variation_swap' => VariationSwapHandler::class,
            'variation_attach' => VariationAttachHandler::class,
        ];
    }
}
