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

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

/**
 * Represents an HTTP BIND request.
 *
 * @see <a href="http://webdav.org/specs/rfc5842.html#rfc.section.4">RFC 5842, Section 4</a>
 */
public class Bind extends AbstractMethod {

    private final BindInfo bindInfo;

    public Bind(BindInfo bindInfo) {
        this.bindInfo = bindInfo;
    }

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

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

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