<?php

namespace App\Forms\Part;

class SWITCHForm extends PartForm
{
  public function __construct()
  {
    parent::__construct();
  }
  public function action_init_process(string $action, array $formDatas = []): void
  {
    $fields = [
      "code",
      "price",
    ];
    $filters = [
      'clientinfo_uid',
      'serviceinfo_uid',
      'serverinfo_uid',
      'status'
    ];
    $indexFilter     = $filters;
    $batchjobFilters = ['status',];
    $actionButtons = ['view' => ICONS['SEARCH']];
    $batchjobButtons = ['batchjob' => '일괄처리'];
    switch ($action) {
      case 'create':
      case 'create_form':
      case 'modify':
      case 'modify_form':
        $fields = [
          ...$fields,
          'status',
        ];
        break;
      case 'view':
        $fields = [
          ...$fields,
          'clientinfo_uid',
          'serviceinfo_uid',
          'serverinfo_uid',
          'status',
          'created_at'
        ];
        break;
      case 'index':
      case 'download':
        $fields = [
          ...$fields,
          'clientinfo_uid',
          'serviceinfo_uid',
          'serverinfo_uid',
          '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 "status":
        $formRules[$field] = "required|trim|string";
        break;
      default:
        $formRules =  parent::getFormRule($action, $field, $formRules);
        break;
    }
    return $formRules;
  }
}
