package itn.let.cert.ip.web;

import java.time.LocalDateTime;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import egovframework.rte.fdl.security.userdetails.util.EgovUserDetailsHelper;
import itn.com.cmm.LoginVO;
import itn.com.utl.fcc.service.EgovStringUtil;
import itn.let.cert.ip.service.CertLoginLogService;
import itn.let.cert.ip.service.MberCertIpVO;
import itn.let.mail.service.StatusResponse;

/**
 * 
 * @author 		: 이호영
 * @fileName 	: CertIpController.java 
 * @date 		: 2024.11.19
 * @description : 허용 IP 관련 컨트롤러
 * =========================================================== 
 * DATE          AUTHOR   NOTE 
 * ----------------------------------------------------------- *
 * 2024.11.19    이호영          최초 생성
 * 
 * 
 * 
 */
@Controller
public class CertLoginLogController {
	
	
	/* CertLoginLogService */
	@Resource(name = "CertLoginLogService")
	private CertLoginLogService certLoginLogService;
	
	/*
	@RequestMapping(value = {"/cert/ip/selectMberCertIpList.do"})
	public ResponseEntity<StatusResponse> selectMberCertIpList(MberCertIpVO mberCertPhoneVO) throws Exception {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("jsonView");
		
		//로그인 권한정보 불러오기
		LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
		String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
		
		if(userId == null) {
			if(StringUtils.isEmpty(userId)) return ResponseEntity.ok().body(new StatusResponse(HttpStatus.BAD_REQUEST, "로그인 후 이용해 주세요", LocalDateTime.now()));
		}
		mberCertPhoneVO.setMberId(userId);
		return ResponseEntity.ok().body(certLoginLogService.selectMberCertIpList(mberCertPhoneVO));
	}	
	
	
	@RequestMapping(value = {"/cert/ip/insertCertIp.do"})
	public ResponseEntity<StatusResponse> insertCertIp(MberCertIpVO mberCertIpVO) throws Exception {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("jsonView");
		
		//로그인 권한정보 불러오기
		LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
		String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
		
		if(userId == null) {
			if(StringUtils.isEmpty(userId)) return ResponseEntity.ok().body(new StatusResponse(HttpStatus.BAD_REQUEST, "로그인 후 이용해 주세요", LocalDateTime.now()));
		}
		mberCertIpVO.setFrstRegisterId(userId);
		mberCertIpVO.setMberId(userId);
		
		
		return ResponseEntity.ok().body(certLoginLogService.insertCertIp(mberCertIpVO));
	}	
	
	@RequestMapping(value = {"/cert/ip/deleteCertIp.do"})
	public ResponseEntity<StatusResponse> deleteCertIp(MberCertIpVO mberCertIpVO) throws Exception {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("jsonView");
		
		//로그인 권한정보 불러오기
		LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
		String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
		
		if(userId == null) {
			if(StringUtils.isEmpty(userId)) return ResponseEntity.ok().body(new StatusResponse(HttpStatus.BAD_REQUEST, "로그인 후 이용해 주세요", LocalDateTime.now()));
		}
		mberCertIpVO.setLastUpdusrId(userId);
		mberCertIpVO.setMberId(userId);
		
		
		return ResponseEntity.ok().body(certLoginLogService.deleteCertIp(mberCertIpVO));
	}	
		*/
}