<?php

namespace ModulesGarden\HostingQuotaNotifications\App\UI\TemplateSettings\Providers;

use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\DataProviders\BaseModelDataProvider;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Interfaces\AdminArea;
use \ModulesGarden\HostingQuotaNotifications\App\Models\Templates\Templates;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\ResponseTemplates;

/**
 * Description of TemplateSettingsDataProvider
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class TemplateFormDataProvider extends BaseModelDataProvider implements AdminArea
{

    public function __construct()
    {
        parent::__construct('ModulesGarden\HostingQuotaNotifications\App\Models\Templates\Templates');
    }

    public function read()
    {
        parent::read();

        $val                         = $this->data['lang'];
        $this->data['lang']          = [];
        $this->data['lang']['value'] = $val;
    }

    public function create()
    {
        $this->model->fill($this->formData)->save();

        return (new ResponseTemplates\HtmlDataJsonResponse())->setMessageAndTranslate('langAddedSuccesfully')->setStatusSuccess();
    }

    public function update()
    {
        parent::update();
    }

    public function delete()
    {
        $this->model->where('id', $this->formData['id'])->delete();
        return (new ResponseTemplates\HtmlDataJsonResponse())->setMessageAndTranslate('langDeletedSuccesfully');
    }
}
