<?php

namespace App\Controllers\Admin\Equipment;

use Psr\Log\LoggerInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\HTTP\RequestInterface;
use App\Services\Equipment\LineService;
use App\Entities\Equipment\LineEntity;

class LineController extends EquipmentController
{
    public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        parent::initController($request, $response, $logger);
        $this->content_title      = lang("{$this->getService()->getClassName()}.title");
        $this->class_path .= $this->getService()->getClassName();
        $this->uri_path .= strtolower($this->getService()->getClassName('/')) . '/';
        // $this->view_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR;

    }
    public function getService(): LineService
    {
        if (!$this->_service) {
            $this->_service = new LineService();
        }
        return $this->_service;
    }
    //Index,FieldForm관련

    //생성
    protected function create_process(array $formDatas): LineEntity
    {
        //Line 등록
        if (!$this->getService()->getHelper()->isValidCIDR($formDatas['bandwith'])) {
            throw new \Exception("{$formDatas['bandwith']}는 CIDR 형식에 부합되지 않습니다.");
        }
        return parent::create_process($formDatas);
    }
}
