<?php

namespace App\Forms\Auth;

use App\Forms\CommonForm;

class LocalForm extends CommonForm
{
  public function __construct()
  {
    parent::__construct();
  }

  public function getFormRule(string $action, string $field): string
  {
    switch ($field) {
      case "id":
        $rule = sprintf("required|trim|min_length[4]|max_length[20]%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
        break;
      case "passwd":
        $rule = in_array($action, ["create", "create_form"]) ? "required|trim|string" : "permit_empty|trim|string";
        break;
      default:
        $rule = parent::getFormRule($action,  $field);
        break;
    }
    return $rule;
  }
}
