<?php

namespace App\Controllers\Front\Billing;

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

class DepositController extends BillingController
{
    public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        parent::initController($request, $response, $logger);
        $this->_viewDatas['className'] = 'Deposit';
        $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 'update':
                return ["email", "phone"];
                break;
            default:
                return [];
                break;
        }
    }
    protected function getFieldRule(string $field, array $rules, string $action = ""): array
    {
        switch ($field) {
            case "email":
                $rules[$field] = 'required|valid_email';
                break;
            case "phone":
                $rules[$field] = 'required|regex_match[/^[0-9]{3}-[0-9]{4}-[0-9]{4}/]';
                break;
            default:
                $rules = parent::getFieldRule($field, $rules, $action);
                break;
        }
        return $rules;
    }
    public function getFieldFilters(): array
    {
        return [];
    }
    public function getFieldBatchFilters(): array
    {
        return parent::getFieldBatchFilters();
    }

    //Update관련
    //무통장입금결제처리
    protected function update_process($entity)
    {
        //Deposit 결제처리
        $this->_viewDatas['fieldDatas']["type"] = $this->_viewDatas['className'];
        return parent::update_process($entity);
    }
}
