<?php

namespace App\Forms;

use App\Forms\CommonForm;

class MylogForm extends CommonForm
{
  public function __construct()
  {
    parent::__construct();
  }
  public function action_init_process(string $action, array &$formDatas = []): void
  {
    $fields = ['title', 'content'];
    $filters = ['user_uid'];
    $indexFilter = $filters;
    $batchjobFilters = $filters;
    switch ($action) {
      case 'create':
      case 'create_form':
      case 'modify':
      case 'modify_form':
        break;
      case 'view':
        $fields = [...$fields, 'status', 'created_at'];
        break;
      case 'index':
      case 'download':
        $fields = [...$fields, '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 "user_uid":
        $formRules[$field] = "required|int";
        break;
      case "title":
      case "status":
        $formRules[$field] = "required|trim|string";
        break;
      case "content":
        $formRules[$field] = "permit_empty|trim|string";
        break;
      default:
        $formRules = parent::getFormRule($action, $field, $formRules);
        break;
    }
    return $formRules;
  }
}
