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

import java.io.StringReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "KycRes")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = { "code", "ret", "ts", "ttl", "txn", "UidData", "err", "xmlResp" })
public class KycResponse {
	
	@XmlAttribute(name= "code")private String code;
	@XmlAttribute(name= "ret")private String ret;
	@XmlAttribute(name= "ts")private String ts;
	@XmlAttribute(name= "ttl")private String ttl;
	@XmlAttribute(name= "txn")private String txn;
	@XmlAttribute(name= "err")private String err;
	@XmlElementRef(name= "UidData")private UidDataResponse UidData;
	
	private String xmlResp;

	public KycResponse() {
		this.code = "";
		this.ret = "";
		this.ts = "";
		this.ttl = "";
		this.txn = "";
		this.err= "";
		this.UidData = new UidDataResponse();
		this.xmlResp = "";
	}

	public KycResponse(String code, String ret, String ts, String ttl, String txn, String err, UidDataResponse uidData, String xmlResp) {
		this.code = code;
		this.ret = ret;
		this.ts = ts;
		this.ttl = ttl;
		this.txn = txn;
		this.err= err;
		this.UidData = uidData;
		this.xmlResp = xmlResp;
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getRet() {
		return this.ret;
	}

	public void setRet(String ret) {
		this.ret = ret;
	}

	public String getTs() {
		return this.ts;
	}

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

	public String getTtl() {
		return this.ttl;
	}

	public void setTtl(String ttl) {
		this.ttl = ttl;
	}

	public String getTxn() {
		return this.txn;
	}

	public void setTxn(String txn) {
		this.txn = txn;
	}
	
	public String getErr() {
		return err;
	}

	public void setErr(String err) {
		this.err = err;
	}

	public UidDataResponse getUidData() {
		return this.UidData;
	}

	public void setUidData(UidDataResponse uidData) {
		this.UidData = uidData;
	}

	public String getXmlResp() {
		return this.xmlResp;
	}

	public void setXmlResp(String xmlResp) {
		this.xmlResp = xmlResp;
	}

	public static KycResponse buildXMLToKycResponse(String respXML) throws JAXBException {
		JAXBContext context = JAXBContext.newInstance(new Class[] { KycResponse.class });
		Unmarshaller um = context.createUnmarshaller();
		StringReader reader = new StringReader(respXML);
		KycResponse kycResponse= new KycResponse();
		kycResponse = (KycResponse) um.unmarshal(reader);
		return kycResponse;
	}
}
