<?php

namespace App\Helpers\Customer;

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

class ClientHelper extends CustomerHelper
{
    protected ?IncomingRequest $request = null;
    public function __construct(?IncomingRequest $request = null)
    {
        parent::__construct($request);
        $this->setTitleField(ClientModel::TITLE);
    }
    public function getFieldView(string $field, array $viewDatas, array $extras = []): string
    {
        $value = $viewDatas['entity']->$field;
        switch ($field) {
            case 'account_balance':
            case 'coupon_balance':
            case 'point_balance':
                $value = number_format(intval($value));
                break;
            default:
                $value = parent::getFieldView($field, $viewDatas, $extras);
                break;
        }
        if (is_array($value)) {
            echo __METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다";
            exit;
        }
        return $value;
    } //
}
