<?php

namespace App\Forms\Part;

class DISKForm extends PartForm
{
  public function __construct()
  {
    parent::__construct();
  }
  public function form_init_process(string $action, array &$formDatas = []): void
  {
    parent::form_init_process($action, $formDatas);
    $fields = [
      "title",
      "price",
      "used",
      "format",
      "stock",
      "status",
    ];
    $filters = [
      "status",
    ];
    $indexFilter = $filters;
    $batchjobFilters = ['status'];
    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);
  }
  public function getFormRule(string $field, array $formRules): array
  {
    switch ($field) {
      case "used":
        $formRules[$field] = "required|numeric";
        break;
      case "format":
        $formRules[$field] = "required|numeric";
        break;
      default:
        $formRules = parent::getFormRule($field, $formRules);
        break;
    }
    return $formRules;
  }
}
