package com.atlassian.bitbucket.mesh.management;

import com.atlassian.bitbucket.mesh.rpc.v1.RpcGetSupportInfoResponse;

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

import static java.util.Objects.requireNonNull;

class SupportInfo {

    private final GitInfo gitInfo;
    private final Collection<TicketInfo> ticketInfo;

    SupportInfo(@Nonnull GitInfo gitInfo, @Nonnull Collection<TicketInfo> ticketInfo) {
        this.gitInfo = requireNonNull(gitInfo, "gitInfo");
        this.ticketInfo = requireNonNull(ticketInfo, "ticketInfo");
    }

    @Nonnull
    RpcGetSupportInfoResponse toSupportInfoResponse() {
        RpcGetSupportInfoResponse.Builder builder = RpcGetSupportInfoResponse.newBuilder()
                .setGitInfo(gitInfo.toGitInfo());

        ticketInfo.stream()
                .map(TicketInfo::toTicketInfo)
                .forEach(builder::addTicketInfo);

        return builder.build();
    }
}
