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

import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

/**
 * Represents an HTTP UNSUBSCRIBE request.
 * Note that "UNSUBSCRIBE" is a custom HTTP extension, not defined in a standards paper.
 */
public class Unsubscribe extends AbstractMethod {

    private final String subscriptionId;

    public Unsubscribe(String subscriptionId) {
        this.subscriptionId = subscriptionId;
    }

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

    @Override
    public void accept(HttpRequest.Builder httpRequest) {
        super.accept(httpRequest);
        httpRequest.setHeader("SubscriptionId", subscriptionId);
    }

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