<?php

namespace App\Models\Equipment\Part;

use App\Entities\Equipment\Part\DomainEntity;

class DomainModel extends PartModel
{
    const TABLE = "domaininfo";
    const PK = "uid";
    const TITLE = "domain";
    protected $table            = self::TABLE;
    protected $primaryKey       = self::PK;
    protected $returnType       = DomainEntity::class;
    protected $allowedFields = [
        "domain",
        "status",
        "updated_at"
    ];
    public function __construct()
    {
        parent::__construct();
    }
    public function getFormFieldRule(string $action, string $field): string
    {
        if (is_array($field)) {
            throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
        }
        switch ($field) {
            case "domain":
                $rule = "required|trim|valid_domain";
                $rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->table}.{$field}]" : "";
                break;
            case "price":
                $rule  = "required|numeric";
                break;
            default:
                $rule = parent::getFormFieldRule($action, $field);
                break;
        }
        return $rule;
    }
}
