package com.icomsys.main_vm.biz.rcp.conversation.service;

import com.icomsys.main_vm.biz.advice.excep.CustomNotFoundException;
import com.icomsys.main_vm.biz.rcp.conversation.vo.LongtextManagerVO;
import com.icomsys.main_vm.db.jpa.entity.scenario.TbLongtextManager;
import com.icomsys.main_vm.db.jpa.entity.scenario.id.TbLongtextManagerId;
import com.icomsys.main_vm.db.jpa.repo.scenario.TbLongtextManagerRepo;
import com.querydsl.core.QueryResults;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

/**
 * Name : ConversationScenarioGUINodeEditService
 * date : 2023-02-03
 * author :  Mong
 * description :
 * ===========================================================
 * DATE                 AUTHOR                NOTE
 * -----------------------------------------------------------
 * 2023-02-03                Mong             최초 생성
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class ConversationScenarioGUINodeEditService {

    private final TbLongtextManagerRepo tbLongtextManagerRepo;

    public int insertDev(LongtextManagerVO dto) {

        TbLongtextManager vo = new TbLongtextManager();
        vo.setColumnCode(dto.getColumnCode());
        vo.setRfSeq(dto.getRfSeq());
        vo.setTableCode(dto.getTableCode());
        vo.setTextContents(dto.getTextContents());
        vo.setChecksum("Y");
        tbLongtextManagerRepo.save(vo);

        return 0;
    }

    @Transactional(readOnly = true)
    public LongtextManagerVO selectDev(TbLongtextManagerId dto) throws CustomNotFoundException {
        TbLongtextManager result = tbLongtextManagerRepo.findById(dto)
                                .orElseThrow(() -> new CustomNotFoundException("불러올 다이어그램 정보를 찾지 못하였습니다."));
        return new LongtextManagerVO().ofTbLongtextManager(result);
    }

}
