package com.atlassian.bitbucket.internal.scm.git.lfs.model;

import com.google.common.collect.ImmutableMap;
import com.google.common.net.HttpHeaders;

import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static java.util.Objects.requireNonNull;

public class ResponseAction {

    private final Map<String, String> headers;
    private final String href;
    private final OperationType type;

    public ResponseAction(@Nonnull OperationType type, @Nonnull String href, @Nonnull Map<String, String> headers) {
        this.type = requireNonNull(type, "type");
        this.href = requireNonNull(href, "href");
        this.headers = new HashMap<>(requireNonNull(headers, "header"));
    }

    public ResponseAction(@Nonnull OperationType type, @Nonnull String href, @Nonnull String authToken) {
        this.type = requireNonNull(type, "type");
        this.href = requireNonNull(href, "href");
        headers = ImmutableMap.of(HttpHeaders.AUTHORIZATION, requireNonNull(authToken, "authToken"));
    }

    public ResponseAction(@Nonnull OperationType type, @Nonnull String href) {
        this(type, href, Collections.emptyMap());
    }

    @Nonnull
    public Map<String, String> getHeaders() {
        return Collections.unmodifiableMap(headers);
    }

    @Nonnull
    public String getHref() {
        return href;
    }

    @Nonnull
    public OperationType getType() {
        return type;
    }
}
