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

namespace Plesk\MigrationLibV8\SiteImport\Entity\Status;

/**
 * Whole import status of a session - all applications, folders and databases ever migrated within the session.
 *
 * @package Plesk\MigrationLibV8\SiteImport\Entity\Status
 */
class Import
{
    /**
     * @var \Plesk\MigrationLibV8\SiteImport\Entity\Status\Import\Application[]
     */
    private $_applicationsStatus;
    /**
     * @var \Plesk\MigrationLibV8\SiteImport\Entity\Status\Import\Folder[]
     */
    private $_foldersStatus;
    /**
     * @var \Plesk\MigrationLibV8\SiteImport\Entity\Status\Import\Database[]
     */
    private $_databasesStatus;

    /**
     * Import constructor.
     *
     * @param $applicationsStatus \Plesk\MigrationLibV8\SiteImport\Entity\Status\Import\Application[]
     * @param $foldersStatus \Plesk\MigrationLibV8\SiteImport\Entity\Status\Import\Folder[]
     * @param $databasesStatus \Plesk\MigrationLibV8\SiteImport\Entity\Status\Import\Database[]
     */
    public function __construct($applicationsStatus, $foldersStatus, $databasesStatus) {
        $this->_applicationsStatus = $applicationsStatus;
        $this->_foldersStatus = $foldersStatus;
        $this->_databasesStatus = $databasesStatus;
    }

    /**
     * @return \Plesk\MigrationLibV8\SiteImport\Entity\Status\Import\Application[]
     */
    public function getApplicationsStatus()
    {
        return $this->_applicationsStatus;
    }

    /**
     * @return \Plesk\MigrationLibV8\SiteImport\Entity\Status\Import\Folder[]
     */
    public function getFoldersStatus()
    {
        return $this->_foldersStatus;
    }

    /**
     * @return \Plesk\MigrationLibV8\SiteImport\Entity\Status\Import\Database[]
     */
    public function getDatabasesStatus()
    {
        return $this->_databasesStatus;
    }

    /**
     * Get whole import status as array (useful for integration with JavaScript code).
     *
     * @return array
     */
    public function asArray()
    {
        $applicationsStatus = [];
        foreach ($this->getApplicationsStatus() as $applicationStatus) {
            $applicationsStatus[] = $applicationStatus->asArray();
        }

        $foldersStatus = [];
        foreach ($this->getFoldersStatus() as $folderStatus) {
            $foldersStatus[] = $folderStatus->asArray();
        }

        $databasesStatus = [];
        foreach ($this->getDatabasesStatus() as $databaseStatus) {
            $databasesStatus[] = $databaseStatus->asArray();
        }

        return [
            'applications' => $applicationsStatus,
            'folders' => $foldersStatus,
            'databases' => $databasesStatus
        ];
    }
}
