<?php
// Copyright 1999-2017. Plesk International GmbH. All rights reserved.

namespace Plesk\MigrationLibV8\MailImport\Entity\Status;

class Task
{
    private $_status;
    /** @var string|null */
    private $_step;
    /** @var string|null */
    private $_errorId;
    /** @var string|null */
    private $_errorMessage;
    /** @var string|null */
    private $_errorDetails;

    /**
     * Task constructor.
     *
     * @param string|null $status
     * @param string|null $step
     * @param string|null $errorId
     * @param string|null $errorMessage
     * @param string|null $errorDetails
     */
    public function __construct(
        $status=null, $step=null, $errorId=null, $errorMessage=null, $errorDetails=null
    ) {
        $this->_status = $status;
        $this->_step = $step;
        $this->_errorId = $errorId;
        $this->_errorMessage = $errorMessage;
        $this->_errorDetails = $errorDetails;
    }

    /**
     * Get import status of the mail address pair, as string (e.g. "success")
     *
     * @return string|null see constants from \Plesk\MigrationLibV8\MailImport\Entity\Status\Import\Statuses
     */
    public function getStatus()
    {
        return $this->_status;
    }

    /**
     * Get step on which migration is right now (if import is in progress).
     *
     * @return string|null
     */
    public function getStep()
    {
        return $this->_step;
    }

    /**
     * Get error identifier, as string.
     *
     * @return string|null
     */
    public function getErrorId()
    {
        return $this->_errorId;
    }

    /**
     * Get error message, as string.
     *
     * @return string|null
     */
    public function getErrorMessage()
    {
        return $this->_errorMessage;
    }

    /**
     * Get error details, as string.
     *
     * @return string|null
     */
    public function getErrorDetails()
    {
        return $this->_errorDetails;
    }

    /**
     * Return status information for imported mail address pairs as array (useful for integration with JavaScript code).
     *
     * Array has the following keys:
     *    'status' - import status of the mail address pair, as string (e.g. "success")
     *    'step' - step on which import is running, if it is in progress, as string
     *    'error_id' - error identifier, as string (use to perform special actions in case of specific error, e.g.
     *              highlight login/password fileds in case of authentication issue, and so on)
     *    'error_message' - human readable error message
     *    'error_details' - human readable error details
     * @return array
     */
    public function asArray()
    {
        return [
            'status' => $this->getStatus(),
            'step' => $this->getStep(),
            'error_id' => $this->getErrorId(),
            'error_message' => $this->getErrorMessage(),
            'error_details' => $this->getErrorDetails(),
        ];
    }
}
