<?php

namespace App\Services\Equipment;

use App\Entities\Equipment\CodeEntity;
use App\Models\Equipment\CodeModel;
use App\Services\Equipment\EquipmentService;

class CodeService extends EquipmentService
{
    public function __construct(mixed $request = null)
    {
        parent::__construct($request);
        $this->addClassName('Code');
    }
    public function getModelClass(): CodeModel
    {
        return new CodeModel();
    }
    public function getEntityClass(): CodeEntity
    {
        return new CodeEntity();
    }
    public function getFormFields(): array
    {
        return [
            "code",
            "status",
        ];
    }
    public function getFilterFields(): array
    {
        return ['status'];
    }
    public function getBatchJobFields(): array
    {
        return ['status'];
    }
    public function getIndexFields(): array
    {
        return ['code', 'status'];
    }
    //상태변경
    public function setStatus(string $code, string $status): CodeEntity
    {
        //code의 경우 사용가능/사용중으로 설정작업
        $entity = $this->getEntity($code);
        if (!$entity) {
            throw new \Exception("{$code}에 대한 서버코드정보를 찾을수 없습니다.");
        }
        return $this->getModel()->modify($entity, ['status' => $status]);
    }
}
