<?php

namespace CouponsPlus\App\Handlers;

use AllowDynamicProperties;
use CouponsPlus\Original\Collections\Collection;
use CouponsPlus\Original\Events\Handler\EventHandler;

#[\AllowDynamicProperties]
Class IDSLoaderHandler extends EventHandler
{
    protected static $instance;

    protected $numberOfArguments = 1;
    protected $priority = 10;

    static public function instance() : IDSLoaderHandler
    {
        if (!static::$instance) {
            static::$instance = new static;
        }

        return static::$instance;
    }

    public function execute(array $data)
    {
        (object) $self = static::instance();

        if (!($self->{$data['type']} ?? false)) {
            $self->{$data['type']} = new Collection([]);
        }

        $self->{$data['type']} = ($self->{$data['type']})->concat((array) $data['ids']);
    }
}