package com.its.api.its.service.vms;

import com.its.api.its.model.dto.vms.TbVmsSymbLibDto;
import com.its.api.its.repository.vms.TbVmsFormObjectRepository;
import com.its.api.its.repository.vms.TbVmsSymbLibRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

@Slf4j
@Service
public class TbVmsSymbLibVmp0Service extends TbVmsSymbLibService {

    public TbVmsSymbLibVmp0Service(TbVmsSymbLibRepository repo, TbVmsFormObjectRepository formObjectRepository) {
        super("VMP0", repo, formObjectRepository);
    }

    public Integer getNewSymbolId() {
        return getNewSymbolId(6000, 6999);
    }

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