<?php

namespace App\Helpers\Customer;

use App\Models\Customer\AccountModel;
use CodeIgniter\HTTP\IncomingRequest;

class AccountHelper extends CustomerHelper
{
    protected ?IncomingRequest $request = null;
    public function __construct(?IncomingRequest $request = null)
    {
        parent::__construct($request);
        $this->setTitleField(AccountModel::TITLE);
    }
    public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null
    {
        switch ($field) {
            case 'amount':
                $value = number_format($value) . "원";
                break;
            default:
                if (in_array($field, $viewDatas['control']['filter_fields'])) {
                    $value = $viewDatas['control']['filter_optons'][$field][$value]->getTitle();
                }
                break;
        }
        if (is_array($value)) {
            echo __METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다";
            exit;
        }
        return $value;
    }
    public function getListButton(string $action, array $viewDatas, array $extras = []): string
    {
        switch ($action) {
            case 'modify':
                $action = $viewDatas['entity']->getPK();
                break;
            case 'delete':
                $action = "";
                break;
            default:
                $action = parent::getListButton($action, $viewDatas, $extras);
                break;
        }
        return $action;
    }
}
