package com.dbnt.faisp.controller;

import com.dbnt.faisp.authMgt.AuthMgtService;
import com.dbnt.faisp.codeMgt.CodeMgtService;
import com.dbnt.faisp.menuMgt.MenuMgtService;
import com.dbnt.faisp.menuMgt.model.MenuMgt;
import com.dbnt.faisp.organMgt.OrganConfigService;
import com.dbnt.faisp.translator.TranslatorService;
import com.dbnt.faisp.translator.model.Translator;
import com.dbnt.faisp.userInfo.UserInfoService;
import com.dbnt.faisp.userInfo.model.UserInfo;
import lombok.RequiredArgsConstructor;

import java.util.List;

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;


@RestController
@RequiredArgsConstructor
@RequestMapping("/translator")
public class TranslatorController {

  private final MenuMgtService menuMgtService;
  private final UserInfoService userInfoService;
  private final AuthMgtService authMgtService;
  private final CodeMgtService codeMgtService;
  private final TranslatorService translatorSevice;
  private final OrganConfigService organConfigService;
 
  
  @GetMapping("/info")
  public ModelAndView translatorInfo(@AuthenticationPrincipal UserInfo loginUser,Translator translator) {
    ModelAndView mav = new ModelAndView("translator/translator");
    translator.setOrganCdList(organConfigService.selectOrganListWhereUserOgCd(loginUser.getOgCd()));
    translator.setQueryInfo();
    mav.addObject("translatorList", translatorSevice.selectTranslatorList(translator));
    translator.setContentCnt(translatorSevice.selectTranslatorListCnt(translator));
    translator.setPaginationInfo();
    mav.addObject("searchParams", translator);
    return mav;
  }
  
  @PostMapping("/insertTranslatorInfo")
  public String insertTranslatorInfo(@AuthenticationPrincipal UserInfo loginUser,Translator translator) {
	  translator.setWrtNm(loginUser.getUserId());
	  translator.setWrtOrgan(loginUser.getOgCd());
    return translatorSevice.insertTranslatorInfo(translator);
  }
 
  @GetMapping("/translatorEditModal")
  public ModelAndView translatorEditModal(Translator translator){
    ModelAndView mav = new ModelAndView("translator/translatorEditModal");
    mav.addObject("trInfo", translatorSevice.selectTranslatorView(translator));
    return mav;
  }
  
  @PostMapping("/updatetranslatorInfo")
  public void updatetranslatorInfo(@AuthenticationPrincipal UserInfo loginUser,Translator translator) {
	  translator.setWrtNm(loginUser.getUserId());
	  translator.setWrtOrgan(loginUser.getOgCd());
      translatorSevice.updatetranslatorInfo(translator);
  }

}
