<?php

namespace App\Services\Equipment;

use App\Helpers\Equipment\IPHelper;
use App\Models\Equipment\IPModel;
use App\Services\Customer\ClientService;
use App\Services\Customer\ServiceService;
use App\Services\Equipment\EquipmentService;
use App\Services\Equipment\LineService;

class IPService extends EquipmentService
{
    private ?LineService $_lineService = null;
    private ?ClientService $_clientService = null;
    private ?ServiceService $_serviceService = null;
    private ?ServerService $_serverService = null;
    public function __construct()
    {
        parent::__construct(new IPModel(), new IPHelper());
        $this->addClassName('IP');
    }
    public function getFormFields(): array
    {
        return [
            "lineinfo_uid",
            "serverinfo_uid",
            "ip",
            "price",
            "status",
        ];
    }
    public function getFormFilters(): array
    {
        return [
            'old_clientinfo_uid',
            'clientinfo_uid',
            'serverinfo_uid',
            "lineinfo_uid",
            'status'
        ];
    }
    public function getIndexFields(): array
    {
        return [
            'lineinfo_uid',
            'ip',
            'price',
            'status',
            'clientinfo_uid',
            'serverinfo_uid',
            'old_clientinfo_uid'
        ];
    }
    public function getBatchjobFields(): array
    {
        return ['status'];
    }
    final public function getLineService(): LineService
    {
        if (!$this->_lineService) {
            $this->_lineService = new LineService();
        }
        return $this->_lineService;
    }
    final public function getClientService(): ClientService
    {
        if (!$this->_clientService) {
            $this->_clientService = new ClientService();
        }
        return $this->_clientService;
    }
    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;
    }
    //기본기능
    //FieldForm관련용
    public function getFormOption(string $field, $options = []): array
    {
        switch ($field) {
            case 'lineinfo_uid':
                $options = $this->getLineService()->getEntities();
                break;
            case 'old_clientinfo_uid':
                $options = $this->getClientService()->getEntities();
                break;
            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;
    }
    //서비스 설정

    //List 검색용
    //OrderBy 처리
    public function setOrderBy(mixed $field = null, mixed $value = null): void
    {
        $this->getModel()->orderBy('INET_ATON(ip)', 'ASC');
        parent::setOrderBy($field, $value);
    }
}
