<?php

namespace App\Controllers\Admin\Equipment;

use App\Entities\Equipment\ServerEntity;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;

class ServerController extends EquipmentController
{
  public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
  {
    parent::initController($request, $response, $logger);
    if ($this->service === null) {
      $this->service = service('equipment_serverservice');
    }
    $this->addActionPaths('server');
    $this->layouts['footerScripts'][] = '<script src="/js/admin/clipboard.js"></script>';
  }
  //기본 함수 작업
  //Custom 추가 함수
  public function create_form_process(array $formDatas = []): array
  {
    $formDatas = parent::create_form_process($formDatas);
    $formDatas['code'] = sprintf("%d%dXX-M%d", date("y"), ceil((int)date("m") / 3), $this->service->getNextPK());
    return $formDatas;
  }

  protected function modify_form_result_process(string $action): string|RedirectResponse
  {
    return $this->action_render_process($action, $this->getViewDatas(), $this->request->getVar('ActionTemplate') ?? 'server');
  }
}
