package com.atlassian.stash.internal.idx;

import com.atlassian.bitbucket.idx.IndexingContext;
import com.atlassian.bitbucket.repository.Repository;

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

import static java.util.Objects.requireNonNull;

public class DefaultIndexingContext implements IndexingContext {

    private final Map<String, Object> propertyMap;
    private final Repository repository;

    public DefaultIndexingContext(@Nonnull Repository repository) {
        this.repository = requireNonNull(repository, "repository");

        propertyMap = new HashMap<>();
    }

    @Override
    @SuppressWarnings("unchecked")
    public <T> T get(String key) {
        return (T) propertyMap.get(key);
    }

    @Nonnull
    @Override
    public Repository getRepository() {
        return repository;
    }

    @Override
    public Object put(String key, Object value) {
        return propertyMap.put(key, value);
    }

    @Override
    public Object remove(String key) {
        return propertyMap.remove(key);
    }

    @Override
    public String toString() {
        return "DefaultIndexingContext{" +
                "repository=" + repository +
                ", propertyMap=" + propertyMap +
                '}';
    }
}
