<?php

namespace App\Models\Equipment;

use App\Entities\Equipment\ServerPartEntity;

class ServerPartModel extends EquipmentModel
{
    const TABLE = "serverinfo_partinfo";
    const PK = "uid";
    const TITLE = "uid";
    protected $table            = self::TABLE;
    protected $primaryKey       = self::PK;
    protected $returnType       = ServerPartEntity::class;
    protected $allowedFields = [
        "partinfo_uid",
        "serverinfo_uid",
        "serviceinfo_uid",
        "type",
        "billing",
        "amount",
        "cnt",
        "extra",
        "updated_at"
    ];
    public function __construct()
    {
        parent::__construct();
    }
    final 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 "partinfo_uid":
            case "serverinfo_uid":
            case "billing":
            case "cnt":
            case "amount":
                $rule  = "required|numeric";
                break;
            case "serviceinfo_uid":
                $rule = "permit_empty|numeric";
                break;
            case "type":
                $rule = "required|trim|string";
                break;
            default:
                $rule = parent::getFormFieldRule($action, $field);
                break;
        }
        return $rule;
    }
}
