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

import org.xbib.io.webdav.api.PropEntry;
import org.xbib.io.webdav.client.ProppatchInfo;
import org.xbib.io.webdav.common.DavPropertyNameSet;
import org.xbib.io.webdav.common.DavPropertySet;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.List;

/**
 * Represents an HTTP PROPPATCH request.
 *
 * @see <a href="http://webdav.org/specs/rfc4918.html#rfc.section.9.2">RFC 4918, Section 9.2</a>
 */
public class Proppatch extends AbstractMethod {

    private final ProppatchInfo proppatchInfo;

    public Proppatch(List<? extends PropEntry> changeList) {
        this(new ProppatchInfo(changeList));
    }

    public Proppatch(DavPropertySet setProperties, DavPropertyNameSet removeProperties) {
        this(new ProppatchInfo(setProperties, removeProperties));
    }

    public Proppatch(ProppatchInfo proppatchInfo) {
        this.proppatchInfo = proppatchInfo;
    }

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

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

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