package in.gov.digilocker.uidai.services.resources;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.springframework.stereotype.Component;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

@Component
public class DemoAuthPIDBlock {

	private String ts;
	private String pidVer;
	private String wadh;
	private String ms;
	private String mv;
	private String name;
	private String lname;
	private String lmv;
	private String gender;
	private String dob;
	private String dobt;
	private String age;
	private String phone;
	private String email;
	private String co;
	private String house;
	private String street;
	private String lm;
	private String loc;
	private String vtc;
	private String subdist;
	private String dist;
	private String state;
	private String country;
	private String pc;
	private String po;
	private String av;
	private String lav;

	public DemoAuthPIDBlock() {
		this.ts = "";
		this.pidVer = "";
		this.wadh = "";
		this.ms = "";
		this.mv = "";
		this.name = "";
		this.lname = "";
		this.lmv = "";
		this.gender = "";
		this.dob = "";
		this.dobt = "";
		this.age = "";
		this.phone = "";
		this.email = "";

		this.co = "";
		this.house = "";
		this.street = "";
		this.lm = "";
		this.loc = "";
		this.vtc = "";
		this.subdist = "";
		this.dist = "";
		this.state = "";
		this.country = "";
		this.pc = "";
		this.po = "";

		this.av = "";
		this.lav = "";
	}

	public String getTs() {
		return ts;
	}

	public void setTs(String ts) {
		this.ts = ts;
	}

	public String getPidVer() {
		return pidVer;
	}

	public void setPidVer(String pidVer) {
		this.pidVer = pidVer;
	}

	public String getWadh() {
		return wadh;
	}

	public void setWadh(String wadh) {
		this.wadh = wadh;
	}

	public String getMs() {
		return ms;
	}

	public void setMs(String ms) {
		this.ms = ms;
	}

	public String getMv() {
		return mv;
	}

	public void setMv(String mv) {
		this.mv = mv;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLname() {
		return lname;
	}

	public void setLname(String lname) {
		this.lname = lname;
	}

	public String getLmv() {
		return lmv;
	}

	public void setLmv(String lmv) {
		this.lmv = lmv;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getDob() {
		return dob;
	}

	public void setDob(String dob) {
		this.dob = dob;
	}

	public String getDobt() {
		return dobt;
	}

	public void setDobt(String dobt) {
		this.dobt = dobt;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getCo() {
		return co;
	}

	public void setCo(String co) {
		this.co = co;
	}

	public String getHouse() {
		return house;
	}

	public void setHouse(String house) {
		this.house = house;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getLm() {
		return lm;
	}

	public void setLm(String lm) {
		this.lm = lm;
	}

	public String getLoc() {
		return loc;
	}

	public void setLoc(String loc) {
		this.loc = loc;
	}

	public String getVtc() {
		return vtc;
	}

	public void setVtc(String vtc) {
		this.vtc = vtc;
	}

	public String getSubdist() {
		return subdist;
	}

	public void setSubdist(String subdist) {
		this.subdist = subdist;
	}

	public String getDist() {
		return dist;
	}

	public void setDist(String dist) {
		this.dist = dist;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getPc() {
		return pc;
	}

	public void setPc(String pc) {
		this.pc = pc;
	}

	public String getPo() {
		return po;
	}

	public void setPo(String po) {
		this.po = po;
	}

	public String getAv() {
		return av;
	}

	public void setAv(String av) {
		this.av = av;
	}

	public String getLav() {
		return lav;
	}

	public void setLav(String lav) {
		this.lav = lav;
	}

	public String generatePIDXMLForDemoAuth() throws Exception {
		DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

		Document document = docBuilder.newDocument();

		Element rootElement = document.createElement("Pid");

		Attr tsAttr = document.createAttribute("ts");
		tsAttr.setValue(getTs());
		rootElement.setAttributeNode(tsAttr);

		Attr verAttr = document.createAttribute("ver");
		verAttr.setValue(getPidVer());
		rootElement.setAttributeNode(verAttr);
		if ((getWadh() != null) && (!"".equals(getWadh()))) {
			Attr wadhAttr = document.createAttribute("wadh");
			wadhAttr.setValue(this.wadh);
			rootElement.setAttributeNode(wadhAttr);
		}
		Element demoElement = document.createElement("Demo");
		demoElement.setAttribute("lang", "");

		Element piElement = document.createElement("Pi");
		if (!"".equals(getMs())) {
			piElement.setAttribute("ms", getMs());
		}
		if (!"".equals(getMv())) {
			piElement.setAttribute("mv", getMv());
		}
		if (!"".equals(getName())) {
			piElement.setAttribute("name", getName());
		}
		if (!"".equals(getLname())) {
			piElement.setAttribute("lname", getLname());
		}
		if (!"".equals(getLmv())) {
			piElement.setAttribute("lmv", getLmv());
		}
		if (!"".equals(getGender())) {
			piElement.setAttribute("gender", getGender());
		}
		if (!"".equals(getDob())) {
			piElement.setAttribute("dob", getDob());
		}
		if (!"".equals(getDobt())) {
			piElement.setAttribute("dobt", getDobt());
		}
		if (!"".equals(getAge())) {
			piElement.setAttribute("age", getAge());
		}
		if (!"".equals(getPhone())) {
			piElement.setAttribute("phone", getPhone());
		}
		if (!"".equals(getEmail())) {
			piElement.setAttribute("email", getEmail());
		}
		demoElement.appendChild(piElement);
		if (!"".equals(getPc())) {
			Element paElement = document.createElement("Pa");
			if (!"".equals(getMs())) {
				paElement.setAttribute("ms", getMs());
			}
			if (!"".equals(getCo())) {
				paElement.setAttribute("co", getCo());
			}
			if (!"".equals(getHouse())) {
				paElement.setAttribute("house", getHouse());
			}
			if (!"".equals(getStreet())) {
				paElement.setAttribute("street", getStreet());
			}
			if (!"".equals(getLm())) {
				paElement.setAttribute("lm", getLm());
			}
			if (!"".equals(getLoc())) {
				paElement.setAttribute("loc", getLoc());
			}
			if (!"".equals(getVtc())) {
				paElement.setAttribute("vtc", getVtc());
			}
			if (!"".equals(getSubdist())) {
				paElement.setAttribute("subdist", getSubdist());
			}
			if (!"".equals(getDist())) {
				paElement.setAttribute("dist", getDist());
			}
			if (!"".equals(getState())) {
				paElement.setAttribute("state", getState());
			}
			if (!"".equals(getCountry())) {
				paElement.setAttribute("country", getCountry());
			}
			if (!"".equals(getPc())) {
				paElement.setAttribute("pc", getPc());
			}
			if (!"".equals(getPo())) {
				paElement.setAttribute("po", getPo());
			}
			demoElement.appendChild(paElement);
		}
		if ((!"".equals(getMs())) && (!"".equals(getLav())) && (!"".equals(getAv())) && (!"".equals(getLav())) && (!"".equals(getLmv()))) {
			Element pfaElement = document.createElement("Pfa");
			pfaElement.setAttribute("ms", getMs());
			pfaElement.setAttribute("mv", getMv());
			pfaElement.setAttribute("av", getAv());
			pfaElement.setAttribute("lav", getLav());
			pfaElement.setAttribute("lmv", getLmv());
			demoElement.appendChild(pfaElement);
		}
		rootElement.appendChild(demoElement);

		document.appendChild(rootElement);
		String pidXML = Utilities.convertDocumentToString(document);
		return pidXML;
	}
}
