package main_package;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

@ViewScoped
@ManagedBean(name="viewSecureLoan")
public class ViewSecureLoanBean implements Serializable
{
	LoanInfo viewPrsnlLoan;
	UserInfo user_info,guarantorUser1,guarantorUser2;
	String guarantor1,guarantor2,frequency;
	boolean showMobile,showVehical;
	String dealer,product;
	DataBaseMethods dbm=new DataBaseMethods();
	DbYashwant dby = new DbYashwant();
	ArrayList<LoanInfo> otherList=new ArrayList<>();
	String loanName;
	
	public ViewSecureLoanBean()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		viewPrsnlLoan=(LoanInfo) ss.getAttribute("selectedLoan");
		guarantor1=viewPrsnlLoan.getFirstGuarantor();
		guarantor2=viewPrsnlLoan.getSecondGuarantor();
		
		Connection conn=DataBaseConnection.JAVAConnection();
		user_info=dbm.userInfoByShareHolderNo(viewPrsnlLoan.getShareHolderNo(), conn);
		guarantorUser1=dbm.userInfoByShareHolderNo(guarantor1, conn);
		guarantorUser2=dbm.userInfoByShareHolderNo(guarantor2, conn);
		dealer=dby.selectDealer(conn, viewPrsnlLoan.getDealer());
		product=  viewPrsnlLoan.getProduct();
		
		if("14".equalsIgnoreCase(viewPrsnlLoan.getSecurityype())||"15".equalsIgnoreCase(viewPrsnlLoan.getSecurityype()))
		{
			showMobile =true;
		}
		else
		{
			showMobile = false;
		}
		if("14".equalsIgnoreCase(viewPrsnlLoan.getSecurityype()))
		{
			product= dby.selectProduct(conn, viewPrsnlLoan.getProduct());
			loanName="Mobile";
		}
		else {
			loanName="";
		}
		
		if (viewPrsnlLoan.getSecurityype() != null && viewPrsnlLoan.getSecurityype().equalsIgnoreCase("13")) 
		{	
			showVehical=true;
			otherList=dby.selectSecureLoanOtherDeatail(viewPrsnlLoan.getLoanNo(), conn);
		}
		else 
		{
			showVehical= true;
		}
		
		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		frequency=dbm.frequencyLabel(viewPrsnlLoan.getFrequency());
	}
	
	public String backButton()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		String pageName=(String) ss.getAttribute("pageName");
		return pageName;
	}

	public String getGuarantor1() {
		return guarantor1;
	}

	public void setGuarantor1(String guarantor1) {
		this.guarantor1 = guarantor1;
	}

	public String getGuarantor2() {
		return guarantor2;
	}

	public void setGuarantor2(String guarantor2) {
		this.guarantor2 = guarantor2;
	}

	public UserInfo getGuarantorUser1() {
		return guarantorUser1;
	}

	public void setGuarantorUser1(UserInfo guarantorUser1) {
		this.guarantorUser1 = guarantorUser1;
	}

	public UserInfo getGuarantorUser2() {
		return guarantorUser2;
	}

	public void setGuarantorUser2(UserInfo guarantorUser2) {
		this.guarantorUser2 = guarantorUser2;
	}

	public UserInfo getUser_info() {
		return user_info;
	}

	public void setUser_info(UserInfo user_info) {
		this.user_info = user_info;
	}

	public LoanInfo getViewPrsnlLoan() {
		return viewPrsnlLoan;
	}

	public void setViewPrsnlLoan(LoanInfo viewPrsnlLoan) {
		this.viewPrsnlLoan = viewPrsnlLoan;
	}

	public String getFrequency() {
		return frequency;
	}

	public void setFrequency(String frequency) {
		this.frequency = frequency;
	}

	public boolean isShowMobile() {
		return showMobile;
	}

	public void setShowMobile(boolean showMobile) {
		this.showMobile = showMobile;
	}

	public boolean isShowVehical() {
		return showVehical;
	}

	public void setShowVehical(boolean showVehical) {
		this.showVehical = showVehical;
	}

	public ArrayList<LoanInfo> getOtherList() {
		return otherList;
	}

	public void setOtherList(ArrayList<LoanInfo> otherList) {
		this.otherList = otherList;
	}

	public String getDealer() {
		return dealer;
	}

	public void setDealer(String dealer) {
		this.dealer = dealer;
	}

	public String getProduct() {
		return product;
	}

	public void setProduct(String product) {
		this.product = product;
	}

	public String getLoanName() {
		return loanName;
	}

	public void setLoanName(String loanName) {
		this.loanName = loanName;
	}
}
