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

namespace Plesk\MigrationLibV8\SiteImport\Entity\Status;

class Issue
{
    const SEVERITY_ERROR = 'error';
    const SEVERITY_WARNING = 'warning';
    const SEVERITY_INFO = 'info';

    /** @var string */
    private $_severity;
    /** @var float */
    private $_executionDate;
    /** @var string */
    private $_problemText;
    /** @var  string */
    private $_detailsText;

    /**
     * Issue constructor.
     *
     * @param string $severity issue severity - see SEVERITY_* constants
     * @param float $executionDate execution date as timestamp.
     * @param string $problemText problem text - useful for end user of site import.
     * @param string $detailsText|null problem details - which could be useful for admin
     * (e.g. executed CLI commands with their stdout/stderr).
     */
    public function __construct($severity, $executionDate, $problemText, $detailsText)
    {
        $this->_severity = $severity;
        $this->_executionDate = $executionDate;
        $this->_problemText = $problemText;
        $this->_detailsText = $detailsText;
    }

    /**
     * Get issue severity - see SEVERITY_* constants.
     *
     * @return string
     */
    public function getSeverity()
    {
        return $this->_severity;
    }

    /**
     * Get execution date as timestamp.
     *
     * @return float
     */
    public function getExecutionDate()
    {
        return $this->_executionDate;
    }

    /**
     * Get problem text - useful for end user of site import.
     *
     * @return string
     */
    public function getProblemText()
    {
        return $this->_problemText;
    }

    /**
     * Get problem details - which could be useful for admin (e.g. executed CLI commands with their stdout/stderr),
     * stack traces, etc.
     *
     * @return string
     */
    public function getDetailsText()
    {
        return $this->_detailsText;
    }

    /**
     * Get issue information as array (useful for integration with JavaScript code).
     *
     * @return array
     */
    public function asArray()
    {
        return [
            'severity' => $this->getSeverity(),
            'execution_date' => $this->getExecutionDate(),
            'problem_text' => $this->getProblemText(),
            'details_text' => $this->getDetailsText()
        ];
    }
}
