<?php
namespace ModulesGarden\ProxmoxAddon\App\UI\CloudInitScript\Providers;

use ModulesGarden\ProxmoxAddon\App\Models\CloudInitScript;
use ModulesGarden\ProxmoxAddon\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\DataProviders\BaseModelDataProvider;
use function ModulesGarden\ProxmoxAddon\Core\Helper\sl;

class CloudInitScriptDeleteProvider extends BaseModelDataProvider
{


    /**
     * CloudInitScriptProvider constructor.
     * @param string $model
     */
    public function __construct()
    {
        parent::__construct(CloudInitScript::class);
    }

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

    public function deleteMass()
    {

        if (!$this->getRequestValue('massActions'))
        {
            return;
        }
        CloudInitScript::destroy($this->getRequestValue('massActions'));
        return (new HtmlDataJsonResponse())->setMessageAndTranslate('The selected Cloud-Init script have been deleted successfully')
            ->setStatusSuccess()
            ->setCallBackFunction($this->callBackFunction);
    }
}