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

import org.xbib.io.webdav.client.LabelInfo;
import org.xbib.io.webdav.common.DepthHeader;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

/**
 * Represents an HTTP LABEL request.
 *
 * @see <a href="http://webdav.org/specs/rfc3253.html#rfc.section.8.2">RFC 3253, Section 8.2</a>
 */
public class Label extends AbstractMethod {

    private final LabelInfo labelInfo;

    public Label(LabelInfo labelInfo) {
        this.labelInfo = labelInfo;
    }

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

    @Override
    public void accept(HttpRequest.Builder httpRequest) {
        super.accept(httpRequest);
        DepthHeader dh = new DepthHeader(labelInfo.getDepth());
        httpRequest.setHeader(dh.getHeaderName(), dh.getHeaderValue());
    }

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

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