package in.gov.digilocker.uidai.logs.fpmodal;

import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.springframework.stereotype.Component;

@XmlRootElement(name = "PidData")
@XmlAccessorType(XmlAccessType.NONE)
@Component
public class BiomatricData {

	@XmlElement(name = "Resp") Response Resp;
	@XmlElement(name = "DeviceInfo") DeviceInfo DeviceInfo;
	@XmlElement(name = "Skey") Skey Skey;
	@XmlElement(name = "Data") Data Data;
	@XmlElement(name = "Hmac") String Hmac;

	public BiomatricData() {
		this.Resp = new Response();
		this.DeviceInfo = new DeviceInfo();
		this.Skey = new Skey();
		this.Hmac = "";
		this.Data = new Data();
	}

	public Response getResp() {
		return Resp;
	}

	public void setResp(Response resp) {
		Resp = resp;
	}

	public DeviceInfo getDeviceInfo() {
		return DeviceInfo;
	}

	public void setDeviceInfo(DeviceInfo deviceInfo) {
		DeviceInfo = deviceInfo;
	}

	public Skey getSkey() {
		return Skey;
	}

	public void setSkey(Skey skey) {
		Skey = skey;
	}

	public Data getData() {
		return Data;
	}

	public void setData(Data data) {
		Data = data;
	}

	public String getHmac() {
		return Hmac;
	}

	public void setHmac(String hmac) {
		Hmac = hmac;
	}

	public static BiomatricData buildXMLToBioMatricData(String biomatricRes) throws JAXBException {
		JAXBContext context = JAXBContext.newInstance(new Class[] { BiomatricData.class });
		Unmarshaller um = context.createUnmarshaller();
		StringReader reader = new StringReader(biomatricRes);
		BiomatricData bioResponse = new BiomatricData();
		bioResponse = (BiomatricData) um.unmarshal(reader);
		return bioResponse;
	}
	
	
	
	public static String buildXMLData(BiomatricData biomatricData) throws JAXBException {
		JAXBContext context = JAXBContext.newInstance(new Class[] { BiomatricData.class });
		Marshaller marshaller = context.createMarshaller();
		StringWriter writer = new StringWriter(); 
		marshaller.marshal(biomatricData, writer);
		return writer.toString();
	}	
}
