<?php

/* * ********************************************************************
 * ProxmoxAddon product developed. (Aug 23, 2018)
 * *
 *
 *  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\UI\TaskHistory\Providers;

use ModulesGarden\ProxmoxAddon as main;
use ModulesGarden\ProxmoxAddon\Core\UI\Interfaces\AdminArea;
use ModulesGarden\ProxmoxAddon\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\DataProviders\BaseModelDataProvider;
use function ModulesGarden\ProxmoxAddon\Core\Helper\sl;

/**
 *
 * Description of RangeVmProvider
 *
 * @author Pawel Kopec <pawelk@modulesgardne.com>
 */
class TaskHistoryProvider extends BaseModelDataProvider implements AdminArea
{

    public function __construct()
    {
        parent::__construct(main\App\Models\TaskHistory::class);
    }


    public function delete()
    {
        parent::delete();
        sl('lang')->addReplacementConstant('name', $this->formData['name']);
        return (new HtmlDataJsonResponse())->setMessageAndTranslate('Task History :name: has been deleted successfully');
    }

    public function deleteMass()
    {

        if (!$this->getRequestValue('massActions'))
        {
            return;
        }
        main\App\Models\TaskHistory::destroy($this->getRequestValue('massActions'));
        return (new HtmlDataJsonResponse())->setMessageAndTranslate('The selected task history have been deleted successfully')
            ->setStatusSuccess()
            ->setCallBackFunction($this->callBackFunction);
    }
}
