<?php

namespace App\Models\Equipment\Part;

use App\Entities\Equipment\Part\IpEntity;

class IpModel extends PartModel
{
    const TABLE = "ipinfo";
    const PK = "uid";
    const TITLE = "ip";
    protected $table            = self::TABLE;
    protected $primaryKey       = self::PK;
    protected $returnType       = IpEntity::class;
    protected $allowedFields = [
        "lineinfo_uid",
        "ip",
        "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 "lineinfo_uid":
                $rule  = "required|numeric";
                break;
            case "price":
                $rule  = "if_exist|numeric";
                break;
            case "ip":
                $rule = "required|trim|valid_ip[both]"; //ipv4 , ipv6 , both(ipv4,ipv6)
                break;
            default:
                $rule = parent::getFormFieldRule($action, $field);
                break;
        }
        return $rule;
    }
}
