package com.atlassian.bitbucket.mesh.git.content;

import com.atlassian.bitbucket.mesh.rpc.v1.RpcDirectory;
import com.atlassian.bitbucket.mesh.util.BuilderSupport;
import com.google.protobuf.ByteString;

import javax.annotation.Nonnull;

public class Directory {

    private final String contentId;
    private final String path;

    private Directory(Builder builder) {
        contentId = builder.contentId;
        path = builder.path;
    }

    @Nonnull
    public String getContentId() {
        return contentId;
    }

    @Nonnull
    public String getPath() {
        return path;
    }

    @Nonnull
    public RpcDirectory toDirectory() {
        return RpcDirectory.newBuilder()
                .setContentId(contentId)
                .setPath(ByteString.copyFromUtf8(path))
                .build();
    }

    public static class Builder extends BuilderSupport {

        private final String contentId;
        private final String path;

        public Builder(@Nonnull String path, @Nonnull String contentId) {
            this.contentId = requireNonBlank(contentId, "contentId");
            this.path = requireNonBlank(path, "path");
        }

        @Nonnull
        public Directory build() {
            return new Directory(this);
        }
    }
}
