package idc;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import idc.client.command.IdcClientDBListCmd;
import idc.model.*;
import idc.service.command.*;


/**
 * Servlet implementation class IdcServiceFrontController
 */
@WebServlet("*.sev")
public class IdcServiceFrontController extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private static final String SERVICE_PATH="/jsp/service/";
    /**
     * @see HttpServlet#HttpServlet()
     */
    public IdcServiceFrontController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setHeader("Pragma", "No-cache");
		response.setDateHeader("Expires", 0);
		response.setHeader("Cache-Control","no-Cache");
		response.setHeader("Cache-Control","no-store");
		response.setContentType("charset='utf-8'");
		
		request.setCharacterEncoding("UTF-8");
		
		String requestURI = request.getRequestURI();
		String contextPath = request.getContextPath();
		String cmdURI = requestURI.substring(contextPath.length());
		
		IdcCmd cmd = null;
		String viewPage = "LayoutPage.jsp";
		Object obj=request.getSession().getAttribute("member");
		if(obj!=null)
		{
			//서비스 화면 리스트
			if(cmdURI.equals("/serviceList.sev")){
				cmd = new IdcServiceListCmd();						
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"serviceList.jsp");
			}
			
			//서비스 정보에서 고객 선택시 서비스 세부 정보 보기
			if(cmdURI.equals("/serviceDetail.sev")){
				cmd = new IdcServiceDetailCmd();						
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"serviceDetail.jsp");
			}
			
			//서비스 정보에서 서비스 선택시 세부 정보 보기
			if(cmdURI.equals("/serviceDetailSolo.sev")){
				cmd = new IdcServiceDetailSoloCmd();						
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"serviceDetailSolo.jsp");
			}
			//서비스 등록 화면 제공
			if(cmdURI.equals("/serviceWriteForm.sev")){
				cmd = new IdcServiceWriteFormCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"serviceWrite.jsp");
			}
			
			//서비스 등록 처리
			if(cmdURI.equals("/serviceWrite.sev")){
				cmd = new IdcServiceWriteCmd();
				cmd.execute(request, response);
				viewPage="serviceList.sev";
			}
			
			//VPN 등록 화면 제공
			if(cmdURI.equals("/vpnWriteForm.sev")){
				cmd = new IdcVpnWriteForm();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"vpnWriteForm.jsp");
			}
					
			//VPN 등록 처리
			if(cmdURI.equals("/vpnWriteHandle.sev")){
				cmd = new IdcVpnWriteHandleCmd();
				cmd.execute(request, response);
				viewPage="serviceList.sev";
			}
			
					
			//서비스 관리 과금처리
			if(cmdURI.equals("/serviceAccounting.sev")){		
				cmd = new IdcServiceAccountingCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"serviceAccounting.jsp");
			}
			
			//서비스 관리 과금처리 진행
			if(cmdURI.equals("/serviceAccountHandle.sev")){		
				cmd = new IdcServiceAccountingHandleCmd();
				cmd.execute(request, response);
				viewPage="serviceAccounting.sev";
			}
			
			//서비스 등록 및 부가서비스 페이지
			if(cmdURI.equals("/additionalService.sev")){							
				cmd = new IdcServiceAdditionalCmd();
				cmd.execute(request, response);			
				request.setAttribute("TargetFile", SERVICE_PATH+"additionalService.jsp");
			}
			
			//VPN에 1회성 서비스 추가하기
			if(cmdURI.equals("/additionalService_vpn.sev")){							
				cmd = new IdcServiceAdditionalVPNCmd();
				cmd.execute(request, response);			
				request.setAttribute("TargetFile", SERVICE_PATH+"additionalService_vpn.jsp");
			}
			
			//부가서비스 추가(ip/cs추가)
			if(cmdURI.equals("/ipAdd.sev")){
				cmd = new IdcServiceIpAddCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"ipAdd.jsp");
			}
			
			//부가서비스 추가처리
			if(cmdURI.equals("/ipAddHandle.sev")){
				cmd = new IdcServiceAddHandleCmd();
				cmd.execute(request, response);
				viewPage="additionalService.sev";
			}
			
			//1회성 서비스 추가
			if(cmdURI.equals("/etcManage.sev")){
				cmd = new IdcServiceEtcManageCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"etcManage.jsp");
			}
			
			//1회성 서비스 추가처리
			if(cmdURI.equals("/etcHandle.sev")){
				cmd = new IdcServiceEtcHandleCmd();
				cmd.execute(request, response);			
				String vpnFlag = request.getParameter("vpnFlag");
				
				if(vpnFlag.equals("true")){
					viewPage="additionalService_vpn.sev";
				}else{
					viewPage="additionalService.sev";
				}
				
			}
			
			//기타 부가서비스 추가하기.
			if(cmdURI.equals("/IdcETCAddForm.sev")){
				cmd = new IdcETCAddFormCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"IdcETCAddForm.jsp");
			}
			//기타 부가서비스 등록하기.
			if(cmdURI.equals("/IdcETCAdd.sev")){
				cmd = new IdcETCAddCmd();
				cmd.execute(request, response);
				viewPage="additionalService.sev";
			}
			
			//vpc-cs추가
			if(cmdURI.equals("/addVPC.sev")){
				cmd = new IdcVPCWriteCmd();
				cmd.execute(request, response);			
				request.setAttribute("TargetFile", SERVICE_PATH+"addVPC.jsp");
			}
	
			//vpc-cs2추가
			if(cmdURI.equals("/addVPC2.sev"))
			{
				request.setAttribute("TargetFile", SERVICE_PATH+"addVPC2.jsp");
			}
			//vpc-cs추가 처리
			if(cmdURI.equals("/addVPCHandle.sev")){
				cmd = new IdcVPCWriteHandleCmd();
				cmd.execute(request, response);			
				viewPage="vpcInfo.sev";
			}
			
			//kcs추가 
			if(cmdURI.equals("/addKCS.sev")){
				cmd = new IdcKCSWriteCmd();
				cmd.execute(request, response);			
				request.setAttribute("TargetFile", SERVICE_PATH+"addKCS.jsp");
			}
			//kcs2추가 
			if(cmdURI.equals("/addKCS2.sev")){
				request.setAttribute("TargetFile", SERVICE_PATH+"addKCS2.jsp");
			}
			//kcs추가 처리
			if(cmdURI.equals("/addKCSHandle.sev")){
				cmd = new IdcKCSWriteHandleCmd();
				cmd.execute(request, response);			
				viewPage="vpcInfo.sev?csInfoFlag=false";			
			}
			
			//cs정보 보기		
			if(cmdURI.equals("/vpcInfo.sev")){
				cmd = new IdcCSInfoCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"vpcInfo.jsp");
			}
			
			//vcs정보 수정창
			if(cmdURI.equals("/vpcUpdate.sev")){
				cmd = new IdcCSInfoUpdateCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH + "vpcUpdate.jsp");
			}
			
			//vcs정보 수정처리
			if(cmdURI.equals("/vpcUpdateHandle.sev")){
				cmd = new IdcCSInfoUpdateHandleCmd();
				cmd.execute(request, response);
				viewPage="vpcInfo.sev";
			}
			
			//ktcs 정보 수정창
			if(cmdURI.equals("/ktcsUpdate.sev")){
				cmd = new IdcKtCSInfoUpdateCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH + "ktcsUpdate.jsp");
			}
			
			//ktcs 정보 수정처리
			if(cmdURI.equals("/ktcsUpdateHandle.sev")){
				cmd = new IdcKtCSInfoUpdateHandleCmd();
				cmd.execute(request, response);
				viewPage="vpcInfo.sev?csInfoFlag=false";
			}
			
													
			//방어존 추가
			if(cmdURI.equals("/addDeffence1.sev")){
				cmd = new IdcDeffenceWriteCmd();
				cmd.execute(request, response);			
				request.setAttribute("TargetFile", SERVICE_PATH+"addDeffence1.jsp");
			}
					
			//방어존 추가 처리
			if(cmdURI.equals("/addDeffenceHandle.sev")){
				cmd = new IdcDeffenceWriteHandleCmd();
				cmd.execute(request, response);			
				viewPage="serviceList.sev";
			}
			
			//방어존 리스트 만들기
			if(cmdURI.equals("/deffenceInfo.sev")){
				cmd = new IdcDefenceInfoCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"deffenceInfo.jsp");
			}
			
			//MK 방어존 리스트 만들기
			if(cmdURI.equals("/DefenseInfoMK.sev")){
				cmd = new IdcDefenceInfoCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"DefenseInfoMK.jsp");
			}
			if(cmdURI.equals("/DefenseNewMK.sev")){
				cmd = new IdcDefenceInfoCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"DefenseNewMK.jsp");
			}	
			if(cmdURI.equals("/DefenseModifyMK.sev")){
				cmd = new IdcDefenceInfoCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"DefenseModifyMK.jsp");
			}	
			//방어존 리스트에 추가창   
			if(cmdURI.equals("/addD1add.sev")){
				cmd = new IdcAddDadd1Cmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"addD1add.jsp");
			}
			//방어존 리스트에 추가 처리
			if(cmdURI.equals("/addD1addHandle.sev")){
				cmd = new IdcAddDadd1HandleCmd();
				cmd.execute(request, response);
				viewPage="deffenceInfo.sev";
			}
			//방어존 수정창
			if(cmdURI.equals("/deffenceInfoUpdate.sev")){
				cmd = new IdcDeffenceInfoUpdateCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH + "deffenceInfoUpdate.jsp");
			}
			
			//방어존 수정처리		
			if(cmdURI.equals("/deffenceModifyHandle.sev")){
				cmd = new IdcDeffenceInfoUpdateHandleCmd();
				cmd.execute(request, response);
				viewPage = "deffenceInfo.sev";
			}
			//방어존 부가 수정창
			if(cmdURI.equals("/addD1InfoUpdate.sev")){
				cmd = new IdcDeffenceAddUpdateCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH + "addD1InfoUpdate.jsp");
			}
			//방어존 부가 수정처리
			if(cmdURI.equals("/addD1InfoUpdateHandle.sev")){
				cmd = new IdcDeffenceAddUpdateHandleCmd();
				cmd.execute(request, response);
				viewPage = "deffenceInfo.sev?deffence_case="+request.getParameter("deffence_case");			
			}
			//방어존 삭제처리
			if(cmdURI.equals("/IdcDeffenceDelete.sev"))
			{
				cmd = new IdcDeffenceDeleteCmd();
				cmd.execute(request, response);
				viewPage = "deffenceInfo.sev";
			}
			//서비스리스트 해지처리
			if(cmdURI.equals("/deleteServiceHandle.sev")){
				cmd = new IdcDeleteServiceHandleCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"deleteServiceList.jsp");			
     		}
			//서비스리스트 해지작업
			if(cmdURI.equals("/deleteServiceItem.sev")){
				cmd = new IdcDeleteServiceItemCmd();
				cmd.execute(request, response);
				viewPage="deleteServiceHandle.sev";
			}
			//전체 서비스 해지처리
			if(cmdURI.equals("/deleteServiceAll.sev")){
				cmd = new IdcDeleteALLItemCmd();
				cmd.execute(request, response);
				viewPage="serviceList.sev";
			}
			//개통안내서 페이지
			if(cmdURI.equals("/IdcServiceBillPaperForm.sev"))
			{
				cmd = new IdcServiceBillWriteFormCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"IdcServiceBillPaperForm.jsp");
			}		
			//테스트용 기본페이지.
			if(cmdURI.equals("/DefaultPage.main"))
			{
				cmd = new IdcClientDBListCmd(true);
				cmd.execute(request,response);
				request.setAttribute("TargetFile", SERVICE_PATH+"IdcClientDBList.jsp");
				viewPage="DefaultPage.jsp";
			}
			
			//서비스 정보 수정				
			if(cmdURI.equals("/serviceUpdate.sev")){
				cmd = new IdcServiceUpdateCmd();
				cmd.execute(request, response);			
				viewPage="serviceDetail.sev?";
			}
			if(cmdURI.equals("/serviceUpdateVpn.sev")){
				cmd = new IdcServiceUpdateVpnCmd();
				cmd.execute(request, response);			
				viewPage="serviceDetail.sev?&client_code="+request.getAttribute("client_code");
			}
			//결제금액 수정 모달 처리		
			if(cmdURI.equals("/serviceAmountUpdate.sev")){
				cmd = new IdcServiceAmountUpdateCmd();
				cmd.execute(request, response);
				viewPage="serviceDetail.sev?client_code="+request.getAttribute("client_code");
			}
			//서비스 상세정보에서 서비스 노트(비고)입력하기
			//결제금액 수정 모달 처리		
			if(cmdURI.equals("/IdcServiceNoteUpdate.sev")){
				cmd = new IdcServiceNoteUpdateCmd();
				cmd.execute(request, response);
				viewPage="serviceDetail.sev?client_code="+request.getAttribute("client_code");
			}
			
			//결제처리
			if(cmdURI.equals("/IdcServicePaymentUpdate.sev")){			
				cmd =new IdcServicePaymentUpdateCmd();
				cmd.execute(request, response);//						
				viewPage="serviceDetail.sev?client_code="+request.getAttribute("client_code");
			}
			
	//		부가서비스 해지리스트 
			if(cmdURI.equals("/IdcDeleteSubListForm.sev"))
			{
				cmd = new IdcDeleteSubFormCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", SERVICE_PATH+"IdcDeleteSubForm.jsp");
			}
			
	//		서비스 해지리스트
			if(cmdURI.equals("/IdcDeleteServiceListForm.sev"))
			{
				cmd = new IdcDeleteServiceListFormCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", SERVICE_PATH+"IdcDeleteServiceListForm.jsp");
			}
			
	//		복구용 서비스 해지리스트
			if(cmdURI.equals("/IdcCopyDeleteServiceListForm.sev"))
			{
				cmd = new IdcCopyDeleteServiceListFormCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", SERVICE_PATH+"IdcCopyDeleteServiceListForm.jsp");
			}
			
			//1회성 및 기타 리스트
			if(cmdURI.equals("/etcList.sev"))
			{
				cmd = new IdcEtcListCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", SERVICE_PATH+"etcList.jsp");
			}
			//IP변경 폼
			if(cmdURI.equals("/IdcIPChangeForm.sev"))
			{
				cmd = new IdcIPChangeFormCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", SERVICE_PATH+"IdcIPChangeForm.jsp");
			}
			//IP변경
			if(cmdURI.equals("/IdcIPChange.sev"))
			{
				cmd = new IdcIPChangeCmd();
				cmd.execute(request,response);
				viewPage="additionalService.sev";
			}
			
			//서비스 화면 리스트
			if(cmdURI.equals("/serviceListExcel.sev")){
				cmd = new IdcServiceListExcelCmd();						
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"serviceListExcel.jsp");
			}
			
			//cs 정보 엑셀		
			if(cmdURI.equals("/vpcInfoExcel.sev")){
				cmd = new IdcCSInfoExcelCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"vpcInfoExcel.jsp");
			}
			
			//방어라인 정보 엑셀		
			if(cmdURI.equals("/deffenceInfoExcel.sev")){
				cmd = new IdcDefenceInfoExcelCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", SERVICE_PATH+"deffenceInfoExcel.jsp");
			}
			
			//2025-04-24 choi.jh onetime 기능추가
			//Onetime 사용 목록 보기
			if(cmdURI.equals("/IdcOnetimeList.sev"))
			{
				request.setAttribute("TargetFile", SERVICE_PATH+"IdcOnetimeList.jsp");
			}
			//2025-04-21 choi.jh 포인트 기능추가			
		}
		else
		{
			request.setAttribute("TargetFile", "jsp/main/IdcLoginForm.jsp");
		}
		System.out.println(cmdURI);
		RequestDispatcher dis = request.getRequestDispatcher(viewPage);
		dis.forward(request, response);
	}

}
