<?php

namespace App\Models\Equipment;

use App\Models\CommonModel;

abstract class EquipmentModel extends CommonModel
{
    protected function __construct()
    {
        parent::__construct();
    }

    public function getFormRule(string $action, string $field): string
    {
        if (is_array($field)) {
            throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
        }
        switch ($field) {
            case "title":
                $rule = "required|trim|string";
                $rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[" . $this->getTable() . "." . $field . "]" : "";
                break;
            case "clientinfo_uid":
            case "serviceinfo_uid":
            case "serverinfo_uid":
                $rule  = "permit_empty|trim|string";
                break;
            case "price":
                $rule  = "required|numeric";
                break;
            case "status":
                $rule = "permit_empty|trim|string";
                break;
            default:
                $rule = parent::getFormRule($action, $field);
                break;
        }
        return $rule;
    }
}
