package com.its.op.service.its.vms;

import com.its.op.dao.repository.its.vms.TbVmsFormObjectRepository;
import com.its.op.dao.repository.its.vms.TbVmsSymbLibRepository;
import com.its.op.dto.its.common.UsageCountDto;
import com.its.op.dto.its.vms.TbVmsSymbLibDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.ConcurrentModificationException;

@Slf4j
@Service
public class TbVmsSymbLibSbt4Service extends TbVmsSymbLibService {

    // 대기환경 이미지
    public TbVmsSymbLibSbt4Service(TbVmsSymbLibRepository repo, TbVmsFormObjectRepository formObjectRepository) {
        super("SBT4", 6000, 6999, repo, formObjectRepository);
    }

    @Transactional
    public TbVmsSymbLibDto deleteDataById(Integer id) throws ConcurrentModificationException {
        UsageCountDto usageCount = findUsageCountBySymbolId(id);
        if (usageCount.getCount() > 0) {
            throw new ConcurrentModificationException("사용중인 심볼 라이브러리 입니다. 삭제할 수 없습니다: " + id);
        }
        return deleteById(id);
    }
}
