<?php

namespace App\Forms;

use App\Forms\CommonForm;

class BoardForm extends CommonForm
{
  public function __construct()
  {
    parent::__construct();
  }
  // protected function getValidationRule(string $field, string $rule): array
  // {
  //   switch ($field) {
  //     case 'role':
  //       $field = "{$field}.*";
  //       break;
  //     default:
  //       return parent::getValidationRule($field, $rule);
  //       // break;
  //   }
  //   return array($field, $rule);
  // }
  public function getFormRule(string $action, string $field): string
  {
    switch ($field) {
      case "category":
      case "title":
        $rule = "required|trim|string";
        break;
      case "user_uid":
        $rule = "required|numeric";
        break;
      case "worker_uid":
        $rule = "permit_empty|numeric";
        break;
      case "content":
        $rule = "permit_empty|string";
        break;
      default:
        $rule = parent::getFormRule($action, $field);
        break;
    }
    return $rule;
  }
  public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'atttributes' => []]): array
  {
    $tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"];
    switch ($field) {
      case 'worker_uid':
        foreach ($this->getFormOption_process(service('userservice'), $action, $field, $formDatas) as $tempEntity) {
          $tempOptions[$tempEntity->getPK()] = $tempEntity->getTitle();
          // $options['attributes'][$tempEntity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $tempEntity->getRole())];
        }
        $options['options'] = $tempOptions;
        break;
      default:
        $options = parent::getFormOption($action, $field, $formDatas, $options);
        break;
    }
    return $options;
  }
}
