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.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "OtpRes")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = { "txn", "err", "actn", "code", "ts", "ret", "info", "xmlResp", "msg"})
public class OTPResponse {
	
	@XmlAttribute(name = "txn") private String txn;
	@XmlAttribute(name = "err") private String err;
	@XmlAttribute(name = "actn") private String actn;
	@XmlAttribute(name = "code") private String code;
	@XmlAttribute(name = "ts") private String ts;
	@XmlAttribute(name = "ret") private String ret;
	@XmlAttribute(name = "info") private String info;
	@XmlElement(name = "xmlResp") private String xmlResp;
	@XmlElement(name = "msg") private String msg;

	public OTPResponse() {
		this.txn = "";
		this.err = "";
		this.actn = "";
		this.code = "";
		this.ts = "";
		this.ret = "n";
		this.info = "";
		this.xmlResp = "";
		this.msg= "";
	}

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

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

	public String getErr() {
		return this.err;
	}

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

	public String getActn() {
		return this.actn;
	}

	public void setActn(String actn) {
		this.actn = actn;
	}

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

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

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

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

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

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

	public String getInfo() {
		return this.info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

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

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

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

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