package cz.moneta.test.harness.support.messaging;

/**
 * Response from a messaging operation (send/receive).
 * Provides fluent assertion API for received messages.
 */
public interface MessageResponse {

    /**
     * Asserts that a field has the expected value.
     *
     * @param path    the field path (JSON dot-path for JSON, XPath for XML)
     * @param value   the expected value
     * @return this for method chaining
     */
    MessageResponse andAssertFieldValue(String path, String value);

    /**
     * Asserts that a field is present in the message.
     *
     * @param path the field path
     * @return this for method chaining
     */
    MessageResponse andAssertPresent(String path);

    /**
     * Asserts that a field is NOT present in the message.
     *
     * @param path the field path
     * @return this for method chaining
     */
    MessageResponse andAssertNotPresent(String path);

    /**
     * Asserts that a header has the expected value.
     *
     * @param headerName the header name
     * @param value      the expected value
     * @return this for method chaining
     */
    MessageResponse andAssertHeaderValue(String headerName, String value);

    /**
     * Asserts that the body contains the given substring.
     * Useful for raw text or EBCDIC/UTF-8 encoded messages.
     *
     * @param substring the expected substring
     * @return this for method chaining
     */
    MessageResponse andAssertBodyContains(String substring);

    /**
     * Extracts a value from the message.
     *
     * @param path the path expression
     * @return JsonPathValue for further assertion
     */
    JsonPathValue extract(String path);

    /**
     * Deserializes the message body into a Java object.
     *
     * @param type the target class
     * @param <T>  the target type
     * @return the deserialized object
     */
    <T> T mapTo(Class<T> type);

    /**
     * Returns the received message.
     *
     * @return the message
     */
    ReceivedMessage getMessage();

    /**
     * Returns the message body.
     *
     * @return the body
     */
    String getBody();

    /**
     * Returns a header value.
     *
     * @param name the header name
     * @return the header value or null
     */
    String getHeader(String name);
}
