<?php

namespace App\Models\Equipment;

use App\Entities\Equipment\ServerPartEntity;

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