<?php

namespace App\Forms\Customer\Wallet;

class AccountForm extends WalletForm
{
  public function __construct()
  {
    parent::__construct();
  }
  public function form_init_process(string $action, array &$formDatas = []): void
  {
    parent::form_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 '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($fields);
    $this->setFormFilters($filters);
    $this->setFormOptions($filters, $formDatas);
    $this->setIndexFilters($indexFilter);
    $this->setBatchjobFilters($batchjobFilters);
    $this->setActionButtons($actionButtons);
    $this->setBatchjobButtons($batchjobButtons);
  }

  public function getFormRule(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($field, $formRules);
        break;
    }
    return $formRules;
  }
}
