<?php

namespace ThurData\Servers\KerioEmail\App\UI\Admin\LoggerManager\Providers;

use ThurData\Servers\KerioEmail\Core\UI\Interfaces\AdminArea;
use \ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseModelDataProvider;
use \ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates;

/**
 * CategoryDataProvider
 *
 * @autor ThurData <info@thurdata.ch>
 */
class LoggerDataProvider extends BaseModelDataProvider implements AdminArea
{
    
    public function __construct()
    {
        parent::__construct('\ThurData\Servers\KerioEmail\Core\Models\Logger\Model');
    }

    public function delete()
    {
        
        if ($this->formData['id'])
        {
            parent::delete();
            
            return (new ResponseTemplates\HtmlDataJsonResponse())->setMessageAndTranslate('loggerDeletedSuccesfully');           
        }
        
        if ($this->requestObj->get('massActions', []))
        {
            foreach ($this->requestObj->get('massActions', []) as $tldId)
            {
                $this->model->where('id', $tldId)->delete();      
            }
            
            return (new ResponseTemplates\HtmlDataJsonResponse())->setMessageAndTranslate('loggersDeletedSuccesfully');  
        }
    }
    
    public function deleteall()
    {
        $this->model->truncate();
        
        return (new ResponseTemplates\HtmlDataJsonResponse())->setMessageAndTranslate('loggersDeletedSuccesfully');  
    }
}
