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

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

class Database
{
    /** @var string */
    private $_name;
    /** @var string */
    private $_host;
    /** @var string */
    private $_port;
    /** @var string */
    private $_username;
    /** @var string */
    private $_password;
    /** @var \Plesk\MigrationLibV8\SiteImport\Entity\Status\Issue[] */
    private $_issues;
    /** @var string */
    private $_status;

    /**
     * Database constructor.
     *
     * @param $name string
     * @param $host string
     * @param $port string
     * @param $username string
     * @param $password string
     * @param $issues \Plesk\MigrationLibV8\SiteImport\Entity\Status\Issue[]
     * @param $status string
     */
    public function __construct($name, $host, $port, $username, $password, $issues, $status)
    {
        $this->_name = $name;
        $this->_host = $host;
        $this->_port = $port;
        $this->_username = $username;
        $this->_password = $password;
        $this->_issues = $issues;
        $this->_status = $status;
    }

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

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

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

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

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

    /**
     * @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 [
            'name' => $this->getName(),
            'host' => $this->getHost(),
            'port' => $this->getPort(),
            'username' => $this->getUsername(),
            'password' => $this->getPassword(),
            'issues' => $issues,
            'status' => $this->getStatus()
        ];
    }
}
