<?php

/* * ********************************************************************
 * ProxmoxAddon product developed. (Jan 23, 2019)
 * *
 *
 *  CREATED BY MODULESGARDEN       ->       http://modulesgarden.com
 *  CONTACT                        ->       contact@modulesgarden.com
 *
 *
 * This software is furnished under a license and may be used and copied
 * only  in  accordance  with  the  terms  of such  license and with the
 * inclusion of the above copyright notice.  This software  or any other
 * copies thereof may not be provided or otherwise made available to any
 * other person.  No title to and  ownership of the  software is  hereby
 * transferred.
 *
 *
 * ******************************************************************** */

namespace ModulesGarden\ProxmoxAddon\App\Services;

use ModulesGarden\ProxmoxAddon\App\Models\RecoveryVm;

/**
 * Description of RecoveryVmDumpService
 *
 * @author Pawel Kopec <pawelk@modulesgardne.com>
 */
class RecoveryVmDumpService
{

    public function generate()
    {
        $data   = [];
        $date   = date("Y-m-d H:i:s");
        $data[] = 'Recovery VM Dump: ' . $date;
        $data[] = "";
        foreach (RecoveryVm::get() as $recoveryVm)
        {
            /* @var $recoveryVm RecoveryVm */
            try
            {
                $data[] = "[ID] #{$recoveryVm->id}";
                $data[] = "[LAST UPDATE] {$recoveryVm->last_update}";
                $data[] = "[HOSTING ID] #{$recoveryVm->service_id}";
                $data[] = "[CLIENT] #{$recoveryVm->client_id} {$recoveryVm->hosting->client->firstname} {$recoveryVm->hosting->client->lastname}";
                $data[] = "[NODE] {$recoveryVm->node}";
                $data[] = "[VMID] {$recoveryVm->vmid}";
                $data[] = "[VIRTUALIZATION] {$recoveryVm->virtualization}";
                $data[] = "[CONFIG]: ";
                $data[] = $recoveryVm->config;
                $data[] = "";
                $data[] = "[STATUS]: ";
                $data[] = $recoveryVm->status;
                $data[] = "";
                $data[] = "[DNS]: ";
                $data[] = $recoveryVm->dns;
                $data[] = "";
                $data[] = "-------------------------------------------------------------------";
                $data[] = "";
            }
            catch (\Exception $ex)
            {
            }
        }
        return implode("\r\n", $data);
    }

}
