<?php

namespace App\Services\Equipment;

use App\Helpers\Equipment\SwitchHelper;
use App\Models\Equipment\SwitchModel;
use App\Services\Customer\ServiceService;
use App\Services\Equipment\EquipmentService;

class SwitchService extends EquipmentService
{
    private ?ServiceService $_serviceService = null;
    private ?ServerService $_serverService = null;
    public function __construct()
    {
        parent::__construct(new SwitchModel(), new SwitchHelper());
        $this->addClassName('Switch');
    }
    public function getFormFields(): array
    {
        return [
            "serverinfo_uid",
            "code",
            "price",
            "status",
        ];
    }
    public function getFormFilters(): array
    {
        return [
            'clientinfo_uid',
            'serviceinfo_uid',
            'serverinfo_uid',
            'status'
        ];
    }
    public function getIndexFields(): array
    {
        return [
            'clientinfo_uid',
            'serviceinfo_uid',
            'serverinfo_uid',
            "price",
            'status',
        ];
    }
    public function getBatchjobFields(): array
    {
        return ['clientinfo_uid', 'serverinfo_uid', 'status'];
    }
    public function getServiceService(): ServiceService
    {
        if (!$this->_serviceService) {
            $this->_serviceService = new ServiceService();
        }
        return $this->_serviceService;
    }
    public function getServerService(): ServerService
    {
        if (!$this->_serverService) {
            $this->_serverService = new ServerService();
        }
        return $this->_serverService;
    }
    //기본 기능부분
    public function getFormOption(string $field, array $options = []): array
    {
        switch ($field) {
            case 'serviceinfo_uid':
                $options = $this->getServiceService()->getEntities();
                break;
            case 'serverinfo_uid':
                $options = $this->getServerService()->getEntities();
                break;
            default:
                $options = parent::getFormOption($field, $options);
                break;
        }
        return $options;
    }
    //FieldForm관련용
    //List 검색용
    //OrderBy 처리
    public function setOrderBy(mixed $field = null, mixed $value = null): void
    {
        $this->getModel()->orderBy('code', 'ASC');
        parent::setOrderBy($field, $value);
    }
}
