package com.dbnt.faisp.translator;

import com.dbnt.faisp.menuMgt.mapper.MenuMgtMapper;
import com.dbnt.faisp.menuMgt.model.MenuMgt;
import com.dbnt.faisp.menuMgt.repository.MenuMgtRepository;
import com.dbnt.faisp.translator.mapper.TranslatorMapper;
import com.dbnt.faisp.translator.model.Translator;
import com.dbnt.faisp.translator.model.Translator.TranslatorId;
import com.dbnt.faisp.translator.repository.TranslatorRepository;
import com.dbnt.faisp.userInfo.model.UserInfo;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Transient;

import java.time.LocalDateTime;
import java.util.*;

@Service
@RequiredArgsConstructor
public class TranslatorService {

  private final TranslatorRepository translatorRepository;
  private final TranslatorMapper translatorMapper;
  
  
	public String insertTranslatorInfo(Translator translator) {
		translator.setVersionNo(1);
		translator.setWrtDt(LocalDateTime.now());
		return translatorRepository.save(translator).getTrName();
}


	public List<Translator> selectTranslatorList(Translator translator) {
		return translatorMapper.selectTranslatorList(translator);
	}


	public Integer selectTranslatorListCnt(Translator translator) {
		return translatorMapper.selectTranslatorListCnt(translator);
	}


	public Translator selectTranslatorView(Translator translator) {
		return translatorRepository.findById(new TranslatorId(translator.getTranslatorKey(), translator.getVersionNo())).orElse(null);
	}

	@Transactional
	public void updatetranslatorInfo(Translator translator) {
		translator.setVersionNo(translator.getVersionNo()+1);
		  translatorRepository.save(translator);
	}

  
}
