<?php

namespace App\Controllers\Admin\Cloudflare;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;

class AllowListController extends CloudflareController
{
    public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        parent::initController($request, $response, $logger);
        $this->_className = $this->_className . '/Ddos';
        $this->_model = new \App\Models\Cloudflare\Magictransit\AllowListModel();
        $this->_defines = [
            'index' => [
                'fields' => ['account_uid', 'domain', 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at'],
                'feildFilters'  => ['account_uid', 'development_mode', 'ipv6', 'security_level', 'status'],
            ],
            'excel' => [
                'fields' => ['account_uid', 'domain', 'name_servers', 'original_name_servers', 'plan', 'development_mode', 'ipv6', 'security_level', 'status', 'updated_at', 'created_at'],
                'feildFilters'  => ['account_uid', 'development_mode', 'ipv6', 'security_level', 'status'],
            ],
        ];
        helper('Cloudflare/ddos');
        $this->_viewPath = $this->_viewPath . '/ddos';
        $this->_viewDatas['title'] = lang($this->_className . '.title');
    }

    protected function getIndexFeildFilterForm(string $field, $value, array $feildFilters): string
    {
        switch ($field) {
            default:
                return getFieldForm_DdosHelper($field, $value, $this->getFeildFilterFormOptions($feildFilters));
                break;
        }
    }

    protected function getExcelFileName(): string
    {
        return sprintf("Ddos_%s.xlsx", date('Y-m-d_HH_mm'));
    }
}
