<?php

namespace App\Forms\Equipment;

class LineForm extends EquipmentForm
{
  public function __construct()
  {
    parent::__construct();
  }
  public function form_init_process(string $action, array &$formDatas = []): void
  {
    parent::form_init_process($action, $formDatas);
    $fields = [
      "type",
      "protocol",
      "title",
      "bandwith",
      "start_at",
      "end_at",
    ];
    $filters = [
      "type",
      "protocol",
      "status",
    ];
    $indexFilter = $filters;
    $batchjobFilters = ['type', 'protocol', 'status'];
    $actionButtons = ['view' => ICONS['SEARCH']];
    $batchjobButtons = [];
    switch ($action) {
      case 'view':
        $fields = [...$fields, 'status', 'created_at'];
        break;
      case 'index':
      case 'download':
        $fields = [...$fields, '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 "bandwith":
      case "type":
      case "protocol":
      case "start_at":
        $formRules[$field] = "required|trim|string";
        break;
      case "end_at":
        $formRules[$field] = "permit_empty|valid_date";
        break;
      default:
        $formRules = parent::getFormRule($field, $formRules);
        break;
    }
    return $formRules;
  }
}
