package itn.let.fax.addr.web;

import java.time.LocalDateTime;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.vfs2.util.DelegatingFileSystemOptionsBuilder;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import egovframework.rte.fdl.security.userdetails.util.EgovUserDetailsHelper;
import itn.com.cmm.EgovMessageSource;
import itn.com.cmm.LoginVO;
import itn.com.utl.fcc.service.EgovStringUtil;
import itn.let.fax.addr.service.FaxAddrGroupService;
import itn.let.fax.addr.service.FaxAddrService;
import itn.let.fax.addr.service.FaxAddrVO;
import itn.let.mail.service.StatusResponse;

/**
 * 팩스 주소록 관한 controller 클래스를 정의한다.
 * @author ITN
 * @since 2024.11.08
 * @version 1.0
 * @see
 *
 * <pre>
 * << 개정이력(Modification Information) >>
 *
 *   수정일      수정자           수정내용
 *  -------    --------    ---------------------------
 *   2021.04.08  ITN          최초 생성
 *
 * </pre>
 */
@RestController
public class FaxAddrRestController {

	
	@Resource (name = "FaxAddrService")
	private FaxAddrService faxAddrService;
	
	@Resource (name = "FaxAddrGroupService")
	private FaxAddrGroupService faxAddrGroupService;
	
	/** EgovMessageSource */
	@Resource(name="egovMessageSource")
	EgovMessageSource egovMessageSource;
	
    /**
     *  팩스 주소록 대량등록 저장
     * @param searchVO
     * @param model
     * @return	"/web/mjon/addr/addrMassInsertByTempAjax_advc.do"
     * @throws Exception
     */
	@RequestMapping(value= {"/web/mjon/fax/addr/faxAddrMassInsertByTempAjax_advc.do"})
	public ResponseEntity<StatusResponse> faxAddrMassInsertByTempAjax_advc(
			@RequestBody List<FaxAddrVO> faxAddrListVO
			,ModelMap model) throws Exception{
		
		LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
		String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
		
		if(userId.equals("")) {
			return ResponseEntity.ok(
					new StatusResponse(HttpStatus.UNAUTHORIZED
							, "로그인을 하셔야 이용 가능합니다."
							, LocalDateTime.now()
							)
					);
		}
		
		return ResponseEntity.ok().body(faxAddrService.faxAddrMassInsertByTempAjax_advc(faxAddrListVO, userId));
	} 
}