<?php

namespace ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Traits;


/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 08.10.19
 * Time: 11:22
 * Class ProcesStepHandler
 */
trait ProcessStepHandler
{
    /**
     * array with process in progress
     * @var array
     */
    protected $inProgressProcess = [];

    /**
     * array with completed process
     * @var array
     */
    protected $completedProcess = [];

    /**
     * array with process finished with error status
     * @var array
     */
    protected $errorProcess = [];

    /**
     * @var array
     */
    protected $allProcess = [];

    /**
     * @return array
     */
    public function getInProgress()
    {
        return $this->inProgressProcess;
    }

    /**
     * @return array
     */
    public function getCompleted()
    {
        return $this->completedProcess;
    }

    /**
     * @return array
     */
    public function getErrorProcess()
    {
        return $this->errorProcess;
    }

    /**
     * @return array
     */
    public function getAllProcess()
    {
        return $this->allProcess;
    }

    /**
     * @param $code
     * @return $this
     */
    public function startProcess($code)
    {
        $this->inProgressProcess[$code] = $code;
        $this->allProcess[]      = $code;
        return $this;
    }

    /**
     * @param $code
     * @return $this
     */
    public function stopProcess($code)
    {
        unset($this->inProgressProcess[$code]);
        $this->completedProcess[$code] = $code;
        return $this;
    }

    /**
     * @param $code
     * @param $error
     * @return $this
     */
    public function stopProcessWithError($code, $error)
    {
        unset($this->inProgressProcess[$code]);
        $this->error[$code] = ['code' => $code, 'error' => $error];
        return $this;
    }

    /**
     * @return array
     */
    public function info()
    {
        return [
            'process'    => $this->getAllProcess(),
            'inProgress' => $this->getInProgress(),
            'finished'   => $this->getCompleted(),
            'error'      => $this->getErrorProcess(),
        ];

    }

}