<?php

namespace iwbvel\classes\services\background_process\handlers;

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

use iwbvel\classes\repositories\Product;
use iwbvel\classes\services\background_process\VariationBackgroundProcess;

class ProductCreateHandler implements HandlerInterface
{
    public function handle($item)
    {
        if (empty($item['count'])) {
            return;
        }

        $product_repository = Product::get_instance();
        for ($i = 1; $i <= intval($item['count']); $i++) {
            $product_repository->create();
        }

        $background_process = VariationBackgroundProcess::get_instance();
        $background_process->add_completed_task(intval($item['count']));
    }
}
