<?php

namespace App\Forms\Part;

class DISKForm extends PartForm
{
  public function __construct()
  {
    parent::__construct();
  }
  public function action_init_process(string $action, array $formDatas = []): void
  {
    $fields = [
      "title",
      "price",
      "stock",
    ];
    $filters = [
      "status",
    ];
    $indexFilter     = $filters;
    $batchjobFilters = ['status'];
    switch ($action) {
      case 'create':
      case 'create_form':
        break;
      case 'modify':
      case 'modify_form':
        $fields = [...$fields, "format", 'status'];
        break;
      case 'view':
        $fields = [...$fields, "format", 'status', 'created_at'];
        break;
      case 'index':
      case 'download':
        $fields = [...$fields, "format", '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);
  }
  public function getFormRule(string $action, 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($action, $field, $formRules);
        break;
    }
    return $formRules;
  }
}
