package org.xbib.io.webdav.client.methods;

import org.xbib.io.webdav.client.SearchInfo;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

/**
 * Represents an HTTP SEARCH request.
 *
 * @see <a href="http://webdav.org/specs/rfc5323.html#rfc.section.2">RFC 5323, Section 2</a>
 */
public class Search extends AbstractMethod {

    private final SearchInfo searchInfo;

    public Search(SearchInfo searchInfo) {
        this.searchInfo = searchInfo;
    }

    @Override
    public String method() {
        return "SEARCH";
    }

    @Override
    public HttpRequest.BodyPublisher bodyPublisher() {
        return publish(searchInfo);
    }

    @Override
    public boolean succeeded(HttpResponse<?> response) {
        return response.statusCode() == 207;
    }
}
