package com.atlassian.bitbucket.mesh.repository;

import com.atlassian.bitbucket.mesh.rpc.v1.RpcDataStore;
import com.google.common.collect.Lists;

import javax.annotation.Nonnull;
import java.util.List;

import static java.util.Objects.requireNonNull;

public class DataStoreInfo {

    private List<ShardInfo> shards;
    private DataStoreType type;

    DataStoreInfo(@Nonnull DataStoreType type, @Nonnull List<ShardInfo> shardInfo) {
        this.type = requireNonNull(type, "type");
        shards = requireNonNull(shardInfo, "shardInfo");
    }

    @Nonnull
    public List<ShardInfo> getShardInfo() {
        return shards;
    }

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

    @Nonnull
    public RpcDataStore toDataStore() {
        return RpcDataStore.newBuilder()
                .setType(type.toRpc())
                .addAllShards(Lists.transform(shards, ShardInfo::toShard))
                .build();
    }
}
