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

namespace Plesk\MigrationLibV8\SiteImport\Entity\Status\Import;

class Folder
{
    /** @var string */
    private $_sourcePath;
    /** @var string */
    private $_targetPath;
    /** @var \Plesk\MigrationLibV8\SiteImport\Entity\Status\Issue[] */
    private $_issues;
    /** @var string */
    private $_status;

    /**
     * Folder constructor.
     *
     * @param $sourcePath string
     * @param $targetPath string
     * @param $issues \Plesk\MigrationLibV8\SiteImport\Entity\Status\Issue[]
     * @param $status string
     */
    public function __construct($sourcePath, $targetPath, $issues, $status)
    {
        $this->_sourcePath = $sourcePath;
        $this->_targetPath = $targetPath;
        $this->_issues = $issues;
        $this->_status = $status;
    }

    /**
     * @return string
     */
    public function getSourcePath()
    {
        return $this->_sourcePath;
    }

    /**
     * @return string
     */
    public function getTargetPath()
    {
        return $this->_targetPath;
    }

    /**
     * @return \Plesk\MigrationLibV8\SiteImport\Entity\Status\Issue[]
     */
    public function getIssues()
    {
        return $this->_issues;
    }

    /**
     * @return string string see constants from \Plesk\MigrationLibV8\SiteImport\Entity\Status\Import\Statuses
     */
    public function getStatus()
    {
        return $this->_status;
    }

    /**
     * Return status information for imported database as array (useful for integration with JavaScript code).
     *
     * @return array
     */
    public function asArray()
    {
        $issues = [];
        foreach ($this->getIssues() as $issue) {
            $issues[] = $issue->asArray();
        }

        return [
            'source_path' => $this->getSourcePath(),
            'target_path' => $this->getTargetPath(),
            'issues' => $issues,
            'status' => $this->getStatus()
        ];
    }
}
