// Path: src/main/java/cz/tomasdvorak/eet/client/persistence/RequestSerializer.java
// public class RequestSerializer {
// 
//     /**
//      * Convert request to a String representation.
//      */
//     public static String toString(TrzbaType request) {
//         try {
//             final JAXBElement<TrzbaType> trzba = new ObjectFactory().createTrzba(request);
//             JAXBContext context = JAXBContext.newInstance(TrzbaType.class);
//             StringWriter sw = new StringWriter();
//             context.createMarshaller().marshal(trzba, sw);
//             return sw.toString();
//         } catch (JAXBException e) {
//             throw new RequestSerializationException("Failed to serialize EET request to String", e);
//         }
//     }
// 
//     /**
//      * Restore request from a String back to object.
//      */
//     public static TrzbaType fromString(String request) {
//         try {
//             JAXBContext jaxbContext = JAXBContext.newInstance(TrzbaType.class);
//             Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
//             InputStream is = new ByteArrayInputStream(request.getBytes());
//             JAXBElement<TrzbaType> reqestElement = jaxbUnmarshaller.unmarshal(new StreamSource(is), TrzbaType.class);
//             return reqestElement.getValue();
//         } catch (JAXBException e) {
//             throw new RequestSerializationException("Failed to deserialize EET request from String", e);
//         }
//     }
// }


import cz.etrzby.xml.OdpovedType;
import cz.etrzby.xml.TrzbaType;
import cz.tomasdvorak.eet.client.persistence.RequestSerializer;
import cz.tomasdvorak.eet.client.utils.StringUtils;
package cz.tomasdvorak.eet.client.dto;


/**
 * Communication result holding all response data and additionally also all request data.
 * There are defined some additional helper methods for easier access to usual fields (FIK, PKP, BKP)
 */
public class SubmitResult extends OdpovedType {

    private final TrzbaType request;

    public SubmitResult(final TrzbaType request, final OdpovedType response) {
        super();
        setChyba(response.getChyba());
        setHlavicka(response.getHlavicka());
        setPotvrzeni(response.getPotvrzeni());
        withVarovani(response.getVarovani());
        this.request = request;
    }

    /**
     * Get the original request to this response
     */
    public TrzbaType getRequest() {
        return request;
    }

    /**
     * Convert the current request to a String representation. Useful for persisting and/or logging purposes.
     * @return String representation of current request.
     */
    public String serializeRequest()  {
// Path: src/main/java/cz/tomasdvorak/eet/client/persistence/RequestSerializer.java
// public class RequestSerializer {
// 
//     /**
//      * Convert request to a String representation.
//      */
//     public static String toString(TrzbaType request) {
//         try {
//             final JAXBElement<TrzbaType> trzba = new ObjectFactory().createTrzba(request);
//             JAXBContext context = JAXBContext.newInstance(TrzbaType.class);
//             StringWriter sw = new StringWriter();
//             context.createMarshaller().marshal(trzba, sw);
//             return sw.toString();
//         } catch (JAXBException e) {
//             throw new RequestSerializationException("Failed to serialize EET request to String", e);
//         }
//     }
// 
//     /**
//      * Restore request from a String back to object.
//      */
//     public static TrzbaType fromString(String request) {
//         try {
//             JAXBContext jaxbContext = JAXBContext.newInstance(TrzbaType.class);
//             Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
//             InputStream is = new ByteArrayInputStream(request.getBytes());
//             JAXBElement<TrzbaType> reqestElement = jaxbUnmarshaller.unmarshal(new StreamSource(is), TrzbaType.class);
//             return reqestElement.getValue();
//         } catch (JAXBException e) {
//             throw new RequestSerializationException("Failed to deserialize EET request from String", e);
//         }
//     }
// }


// Path: src/main/java/cz/tomasdvorak/eet/client/dto/SubmitResult.java
import cz.etrzby.xml.OdpovedType;
import cz.etrzby.xml.TrzbaType;
import cz.tomasdvorak.eet.client.persistence.RequestSerializer;
import cz.tomasdvorak.eet.client.utils.StringUtils;

package cz.tomasdvorak.eet.client.dto;


/**
 * Communication result holding all response data and additionally also all request data.
 * There are defined some additional helper methods for easier access to usual fields (FIK, PKP, BKP)
 */
public class SubmitResult extends OdpovedType {

    private final TrzbaType request;

    public SubmitResult(final TrzbaType request, final OdpovedType response) {
        super();
        setChyba(response.getChyba());
        setHlavicka(response.getHlavicka());
        setPotvrzeni(response.getPotvrzeni());
        withVarovani(response.getVarovani());
        this.request = request;
    }

    /**
     * Get the original request to this response
     */
    public TrzbaType getRequest() {
        return request;
    }

    /**
     * Convert the current request to a String representation. Useful for persisting and/or logging purposes.
     * @return String representation of current request.
     */
    public String serializeRequest()  {
        return RequestSerializer.toString(request);