package idc;

import idc.json.command.IdcAddCSJSONCmd;
import idc.json.command.IdcBusinessGetClientNameCmd;
import idc.json.command.IdcCheckServerUseJSONCmd;
import idc.json.command.IdcGetCSListJSONCmd;
import idc.json.command.IdcGetClientNameCheckJSONCmd;
import idc.json.command.IdcGetClientNameJSONCmd;
import idc.json.command.IdcGetDeleteServiceDetailJSONCmd;
import idc.json.command.IdcGetIPListJSONCmd;
import idc.json.command.IdcGetKCSCodeJSONCmd;
import idc.json.command.IdcGetKCSListJSONCmd;
import idc.json.command.IdcGetLineCodeJSONCmd;
import idc.json.command.IdcGetLinkJSONCmd;
import idc.json.command.IdcGetPaymentListJSONCmd;
import idc.json.command.IdcGetServerCodeJSONCmd;
import idc.json.command.IdcGetServerYJSONCmd;
import idc.json.command.IdcGetUseServerCodeJSONCmd;
import idc.json.command.IdcHistoryListJSONCmd;
import idc.json.command.IdcJsonIDCmd;
import idc.json.command.IdcSendMailSaveJSONCmd;
import idc.json.command.IdcServerListJSONCmd;
import idc.json.command.IdcSetTokenJSONCmd;
import idc.line.command.IdcLineIPWriteCmd;
import idc.model.IdcCmd;

import java.io.IOException;

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

/**
 * Servlet implementation class IdcClientFrontController
 */

@WebServlet("*.jso")
public class IdcJsonFrontController extends HttpServlet
{
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public IdcJsonFrontController()
	{
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		// TODO Auto-generated method stub
		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;

		// ID체크 하는 json처리
		if (cmdURI.equals("/IdcJsonID.jso"))
		{
			cmd = new IdcJsonIDCmd();
			cmd.execute(request, response);
		}
		
		// IdcNewServerList 리스트 가져오기.
		if (cmdURI.equals("/IdcServerListJSON.jso"))
		{
			cmd = new IdcServerListJSONCmd();
			cmd.execute(request, response);
		}
		
		// IdcServiceWriteCMD에서의 호출
		if (cmdURI.equals("/IdcGetServerYJSON.jso"))
		{
			cmd = new IdcGetServerYJSONCmd();
			cmd.execute(request, response);
		}
		
		// ip등록 가능여부 파악 후 ip리스트 뿌려줌
		if (cmdURI.equals("/IdcLineIPWrite.jso"))
		{
			cmd = new IdcLineIPWriteCmd();
			cmd.execute(request, response);
		}
//		퀵버튼 추가 데이터 가져오기.	
		if (cmdURI.equals("/IdcGetLinkJSON.jso"))
		{
			cmd = new IdcGetLinkJSONCmd();
			cmd.execute(request, response);
		}
//		JSON 등록된 장비코드 가져오기 
		if (cmdURI.equals("/IdcGetServerCodeJSON.jso"))
		{
			cmd = new IdcGetServerCodeJSONCmd();
			cmd.execute(request, response);
		}
		//고객 이름 가져오기.
		if(cmdURI.equals("/IdcGetClientName.jso"))
		{
			cmd = new IdcGetClientNameJSONCmd();
			cmd.execute(request,response);
		}
		//고객등록에서 고객이름 가져오기
		if(cmdURI.equals("/IdcCheckClientName.jso"))
		{
			cmd = new IdcGetClientNameCheckJSONCmd();
			cmd.execute(request,response);
		}
//		현재 line에 등록된 IP가져오기.
		if(cmdURI.equals("/IdcGetIPList.jso"))
		{
			cmd = new IdcGetIPListJSONCmd();
			cmd.execute(request,response);
		}
//		HistoryList 가져오기
		if(cmdURI.equals("/IdcHistoryList.jso"))
		{
			cmd = new IdcHistoryListJSONCmd();
			cmd.execute(request,response);
		}
//		삭제 서비스 상세 정보 
		if(cmdURI.equals("/IdcDeleteServiceDetail.jso"))
		{
			cmd = new IdcGetDeleteServiceDetailJSONCmd();
			cmd.execute(request,response);
		}	
//		paymentList 가져오기
		if(cmdURI.equals("/IdcGetPaymentList.jso"))
		{
			cmd = new IdcGetPaymentListJSONCmd();
			cmd.execute(request,response);
		}		
//		business 이름들 얻어오기
		if(cmdURI.equals("/IdcBusinessGetName.jso"))
		{
			cmd = new IdcBusinessGetClientNameCmd();
			cmd.execute(request,response);
		}	
//		cs 새로이 추가하기
		if(cmdURI.equals("/IdcAddCS.jso"))
		{
			cmd = new IdcAddCSJSONCmd();
			cmd.execute(request,response);
		}
//		사용중인 server_code 가져오기
		if(cmdURI.equals("/IdcGetUseServerCode.jso"))
		{
			cmd = new IdcGetUseServerCodeJSONCmd();
			cmd.execute(request,response);
		}
//		남아있는 cs 가져오기
		if(cmdURI.equals("/IdcGetCSList.jso"))
		{
			cmd = new IdcGetCSListJSONCmd();
			cmd.execute(request,response);
		}
//		남아있는 kcs 가져오기
		if(cmdURI.equals("/IdcGetKCSList.jso"))
		{
			cmd = new IdcGetKCSListJSONCmd();
			cmd.execute(request,response);
		}
//		line_code 가져오기
		if(cmdURI.equals("/IdcGetLineCode.jso"))
		{
			cmd = new IdcGetLineCodeJSONCmd();
			cmd.execute(request,response);
		}
//		토큰 설정
		if(cmdURI.equals("/IdcSetToken.jso"))
		{
			cmd = new IdcSetTokenJSONCmd();
			cmd.execute(request,response);
		}
//		kcs 장비명 안겹치나 확인
		if(cmdURI.equals("/IdcGetKcsCode.jso"))
		{
			cmd = new IdcGetKCSCodeJSONCmd();
			cmd.execute(request,response);
		}
//		서버에 MAIL 저장하기
		if(cmdURI.equals("/IdcSendMailSaveJSONCmd.jso"))
		{
			cmd = new IdcSendMailSaveJSONCmd();
			cmd.execute(request,response);
		}
//		서버 삭제시 삭제 가능 여부 확인을 위한 ajax
		if(cmdURI.equals("/IdcCheckServerUse.jso")){
			cmd = new IdcCheckServerUseJSONCmd();
			cmd.execute(request, response);
		}
		System.out.println(cmdURI);
	}

}
