<?php

namespace App\Controllers\Admin;

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

class UserController extends AdminController
{
    public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        parent::initController($request, $response, $logger);
        $this->_model = new UserModel();
        $this->_viewDatas['className'] = 'User';
        $this->_viewPath .= strtolower($this->_viewDatas['className']);
        $this->_viewDatas['title'] = lang($this->_viewDatas['className'] . '.title');
        $this->_viewDatas['class_icon'] = CLASS_ICONS[strtoupper($this->_viewDatas['className'])];
        helper($this->_viewDatas['className']);
    }
    public function getFields(string $action = ""): array
    {
        switch ($action) {
            case 'insert':
                return ["id", "passwd", 'name', "email", "phone", "mobile", "role", "status"];
                break;
            case 'update':
                return ["passwd", 'name', "email", "phone", "mobile", "role", "status"];
                break;
            case "index":
            case "excel":
                return ["id", 'name', "email", "phone", "mobile", "role", "status", 'created_at'];
                break;
            case "view":
                return ["id", 'name', "email", "phone", "mobile", "role", "status", 'updated_at', 'created_at'];
                break;
            default:
                return [];
                break;
        }
    }
    public function getFieldFilters(): array
    {
        return ["role", "status"];
    }
    public function getFieldBatchFilters(): array
    {
        return parent::getFieldBatchFilters();
    }
}
