<?php

namespace App\Forms\Customer\Wallet;

class AccountForm extends WalletForm
{
  public function __construct()
  {
    parent::__construct();
  }
  public function action_init_process(string $action, array &$formDatas = []): void
  {
    parent::action_init_process($action, $formDatas);
    $fields = [
      "clientinfo_uid",
      "bank",
      "title",
      "alias",
      "issue_at",
      "amount",
      "status",
      "content"
    ];
    $filters = [
      "clientinfo_uid",
      "bank",
      "status",
    ];
    $indexFilter = $filters;
    $batchjobFilters = ['bank', 'status'];
    $actionButtons = ['view' => ICONS['SEARCH']];
    $batchjobButtons = [];
    switch ($action) {
      case 'create':
      case 'create_form':
        break;
      case 'modify':
      case 'modify_form':
        $fields = [...$fields, 'status'];
        break;
      case 'view':
        $fields = [...$fields, 'created_at'];
        break;
      case 'index':
      case 'download':
        $fields = [
          "clientinfo_uid",
          "bank",
          "title",
          "alias",
          "issue_at",
          "amount",
          "status",
          'created_at',
        ];
        break;
    }
    $this->setFormFields($fields);
    $this->setFormRules($action, $fields);
    $this->setFormFilters($filters);
    $this->setFormOptions($action, $filters, $formDatas);
    $this->setIndexFilters($indexFilter);
    $this->setBatchjobFilters($batchjobFilters);
    $this->setActionButtons($actionButtons);
    $this->setBatchjobButtons($batchjobButtons);
  }

  public function getFormRule(string $action, string $field, array $formRules): array
  {
    switch ($field) {
      case "bank":
      case "alias":
        $formRules[$field] = "required|trim|string";
        break;
      case "issue_at":
        $formRules[$field] = "required|valid_date";
        break;
      default:
        $formRules = parent::getFormRule($action, $field, $formRules);
        break;
    }
    return $formRules;
  }
}
