<?php

namespace App\Controllers\Admin;

use App\Models\BoardConfigModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;

class BoardConfigController extends \App\Controllers\Admin\AdminController
{
    public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        parent::initController($request, $response, $logger);
        $this->_className .= '/BoardConfig';
        $this->_model = new BoardConfigModel();
        $this->_defines = [
            'insert' => [
                'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload',  'status', 'head', 'tail'],
                'fieldFilters'  => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'],
                'fieldRules' => [
                    'name'              => 'required|string|is_unique[tw_board_conifg.name]',
                    'isaccess'          => 'required|string',
                    'isread'            => 'required|string',
                    'iswrite'           => 'required|string',
                    'isreply'           => 'required|string',
                    'isupload'          => 'required|string',
                    'isdownload'        => 'required|string',
                    'head'              => 'if_exist|string',
                    'tail'              => 'if_exist|string',
                    'status'            => 'if_exist|string',
                ]
            ],
            'update' => [
                'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'head', 'tail'],
                'fieldFilters'  => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'],
                'fieldRules' => [
                    'name'              => 'required|string',
                    'isaccess'          => 'required|string',
                    'isread'            => 'required|string',
                    'iswrite'           => 'required|string',
                    'isreply'           => 'required|string',
                    'isupload'          => 'required|string',
                    'isdownload'        => 'required|string',
                    'head'              => 'if_exist|string',
                    'tail'              => 'if_exist|string',
                    'status'            => 'if_exist|string',
                ]
            ],
            'view' => [
                'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'head', 'tail'],
                'fieldFilters'  => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'],
                'fieldRules' => [
                    'name'              => 'required|string',
                    'isaccess'          => 'required|string',
                    'isread'            => 'required|string',
                    'iswrite'           => 'required|string',
                    'isreply'           => 'required|string',
                    'isupload'          => 'required|string',
                    'isdownload'        => 'required|string',
                    'head'              => 'if_exist|string',
                    'tail'              => 'if_exist|string',
                    'status'            => 'if_exist|string',
                ]
            ],
            'index' => [
                'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'created_at'],
                'fieldFilters'  => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'],
                'batchjobFilters' => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'],
            ],
            'excel' => [
                'fields' => ['name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'created_at'],
                'fieldFilters'  => ['isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status'],
            ],
        ];
        helper($this->_className);
        $this->_viewPath = strtolower($this->_className);
        $this->_viewDatas['title'] = lang($this->_className . '.title');
        $this->_viewDatas['className'] = $this->_className;
    }

    ////Action 모음
    //Insert관련
    final public function insert()
    {
        return $this->insert_procedure();
    }
    //Update관련
    final public function update($uid)
    {
        return $this->update_procedure($uid);
    }
    //Toggle관련
    final public function toggle($uid, string $field)
    {
        return $this->toggle_procedure($uid, $field);
    }
    //Batchjob 관련
    final public function batchjob()
    {
        return $this->batchjob_procedure();
    }
    //Delete 관련
    final public function delete($uid)
    {
        return $this->delete_procedure($uid);
    }
    //View 관련
    final public function view($uid)
    {
        return $this->view_procedure($uid);
    }
    //Index 관련
    final public function index()
    {
        return $this->index_procedure();
    }
    //Excel 관련
    final public function excel()
    {
        return $this->excel_procedure();
    }
}
