<?php

namespace App\Entities\Equipment;

use App\Models\Equipment\ServerModel;

class ServerEntity extends EquipmentEntity
{
    const PK = ServerModel::PK;
    const TITLE = ServerModel::TITLE;

    protected array $nullableFields = [
        'clientinfo_uid',
        'serviceinfo_uid',
        'chassisinfo_uid',
        'switchinfo_uid',
        'ip',
        'viewer',
        'os',
        'format_at',
    ];

    protected $attributes = [
        'clientinfo_uid' => null,
        'serviceinfo_uid' => null,
        'chassisinfo_uid' => null,
        'switchinfo_uid' => null,
        'code' => '',
        'title' => '',
        'type' => '',
        'ip' => null,
        'viewer' => null,
        'os' => null,
        'price' => 0,
        'manufactur_at' => '',
        'format_at' => null,
        'status' => '',
    ];
    public function __construct(array|null $data = null)
    {
        parent::__construct($data);
    }
    final public function getClientInfoUid(): int|null
    {
        $val = $this->clientinfo_uid ?? null;
        return ($val === '' || $val === null) ? null : (int) $val;
    }
    final public function getServiceInfoUid(): int|null
    {
        $val = $this->serviceinfo_uid ?? null;
        return ($val === '' || $val === null) ? null : (int) $val;
    }
    final public function getChassisInfoUid(): int|null
    {
        $val = $this->chassisinfo_uid ?? null;
        return ($val === '' || $val === null) ? null : (int) $val;
    }
    final public function getSwitchInfoUid(): int|null
    {
        $val = $this->switchinfo_uid ?? null;
        return ($val === '' || $val === null) ? null : (int) $val;
    }
    public function setSwitchInfoUid($value)
    {
        $this->attributes['switchinfo_uid'] = ($value === '' || $value === null) ? null : (int) $value;
        return $this;
    }

    //기본기능용
    public function getCustomTitle(mixed $title = null): string
    {
        return sprintf("[%s]%s", $this->getCode(), $title ? $title : $this->getIP());
    }
    final public function getCode(): string
    {
        return $this->code ?? null;
    }
    public function getType(): ?string
    {
        return $this->type ?? null;
    }
    public function getIP(): ?string
    {
        $val = $this->ip ?? null;
        return ($val === '' || $val === null) ? null : $val;
    }

    public function getViewer(): ?string
    {
        return $this->viewer ?? null;
    }

    public function getOS(): ?string
    {
        return $this->os ?? null;
    }
    public function getPrice(): int
    {
        return $this->price ?? 0;
    }
    public function getManufacturAt(): string
    {
        return $this->manufactur_at ?? '';
    }
    public function getFormatAt(): ?string
    {
        $val = $this->format_at ?? null;
        return ($val === '' || $val === null) ? null : $val;
    }
}
