package com.Controller;

import java.io.IOException;
import java.io.PrintWriter;

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 com.Dao.AdminLoginOperation;
import com.Model.Customer;

@WebServlet("/createCustomerReq")
public class Server2_create_customer extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public Server2_create_customer() {
        super();
        // TODO Auto-generated constructor stub
    }

//	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		// TODO Auto-generated method stub
//		response.getWriter().append("Served at: ").append(request.getContextPath());
//	}
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
//		doGet(req, resp);
		PrintWriter out = resp.getWriter();
		System.out.println("Inside the server");
		if(req.getParameter("create_customer_btn").equalsIgnoreCase("Create New A/c")){
			System.out.println("After btn is clicked");
			Customer c = new Customer();
//			c.setcId(req.getParameter("username"));
//			c.setcPwd(req.getParameter("password"));
//			c.setcSsnId(req.getParameter("ssn"));
//			c.setfName(req.getParameter("fname"));
//			c.setlName(req.getParameter("lname"));
//			c.setEmail(req.getParameter("email"));
//			c.setAddress(req.getParameter("address"));
//			c.setContactNo(req.getParameter("contact"));
//			c.setAadharNo(req.getParameter("aadhar"));
//			c.setPanNo(req.getParameter("pan"));
//			c.setAcNo(Integer.parseInt(req.getParameter("account")));
//			c.setInitialAmt(Integer.parseInt(req.getParameter("deposit")));
//			c.setAcStatus(Boolean.parseBoolean(req.getParameter("acStatus")));
			
			c.setcId(req.getParameter("username"));
			c.setcPwd(req.getParameter("password"));
			c.setcSsnId("B12345678");
			c.setfName("Rohan");
			c.setlName("Kujur");
			c.setEmail("test7@gmail.com");
			c.setAddress("A001, xyz colony, Delhi");
			c.setContactNo("9967541238");
			c.setAadharNo("123456954785");
			c.setPanNo("MTJPK234N");
			c.setAcNo(Integer.parseInt("123456856"));
			c.setInitialAmt(Integer.parseInt("3000"));
			c.setAcStatus(Boolean.parseBoolean(req.getParameter("acStatus")));
			
			if(new AdminLoginOperation().insertCustomer(c)>0){
				System.out.println("request approved");
				resp.sendRedirect("adminDashBoard.jsp");
//				req.setAttribute("redirectURL", "adminDashBoard.jsp");
//				req.getRequestDispatcher("adminCreateCustomer.jsp").forward(req, resp);
			}
			else{
				System.out.println("request rejected");
				resp.sendRedirect("ErrorPage.jsp");
//				req.setAttribute("redirectURL", "ErrorPage.jsp");
//				req.getRequestDispatcher("adminCreateCustomer.jsp").forward(req, resp);
			}
		}
		
		
	}

}
