<?php

namespace App\Controllers\Admin\Equipment;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use RuntimeException;

class ServerPartController extends EquipmentController
{
  public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
  {
    parent::initController($request, $response, $logger);
    if ($this->service === null) {
      $this->service = service('equipment_serverpartservice');
    }
    $this->addActionPaths('serverpart');
  }
  //기본 함수 작업
  //Custom 추가 함수
  protected function create_form_process(array $formDatas = []): array
  {
    // Form Default값 설정 (오버라이드 포인트)
    $formDatas = parent::create_form_process($formDatas);
    $formDatas['serverinfo_uid'] = $this->request->getVar('serverinfo_uid') ?? throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 ServerPart는 반드시 서버정보가 필요합니다.");
    $formDatas['type'] = $this->request->getVar('type') ?? throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 ServerPart는 반드시 파트형식 필요합니다.");
    $formDatas['cnt']            = 1;
    //type : CS,IP이면 월비용 기본처리
    switch ($formDatas['type']) {
      case 'CS':
      case 'IP':
        $formDatas['billing'] = PAYMENT['BILLING']['MONTH'];
        break;
      default:
        $formDatas['billing'] = PAYMENT['BILLING']['ONETIME'];
        break;
    }
    return $formDatas;
  }
}
