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

import com.atlassian.bitbucket.mesh.git.AbstractParameters;
import com.atlassian.bitbucket.mesh.repository.Repository;
import com.atlassian.bitbucket.mesh.util.PageRange;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import static java.util.Objects.requireNonNull;

public class ListDirectoryParameters extends AbstractParameters {

    private final String commitId;
    private final PageRange pageRange;
    private final String path;
    private final boolean recursive;
    private final Repository repository;
    private final boolean withSizes;

    private ListDirectoryParameters(Builder builder) {
        super(builder);

        commitId = requireNonNull(builder.commitId, "commitId");
        pageRange = requireNonNull(builder.pageRange, "pageRange");
        path = builder.path;
        recursive = builder.recursive;
        repository = builder.repository;
        withSizes = builder.withSizes;
    }

    @Nonnull
    public String getCommitId() {
        return commitId;
    }

    @Nonnull
    public PageRange getPageRange() {
        return pageRange;
    }

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

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

    public boolean isRecursive() {
        return recursive;
    }

    public boolean isWithSizes() {
        return withSizes;
    }

    public static class Builder extends AbstractBuilder<Builder, ListDirectoryParameters> {

        private final Repository repository;

        private String commitId;
        private PageRange pageRange;
        private String path;
        private boolean recursive;
        private boolean withSizes;

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

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

        @Nonnull
        public Builder commitId(@Nonnull String value) {
            commitId = requireNonBlank(value, "commitId");

            return self();
        }

        @Nonnull
        public Builder pageRange(@Nonnull PageRange value) {
            pageRange = requireNonNull(value, "value");

            return self();
        }

        @Nonnull
        public Builder path(@Nullable String value) {
            path = value;

            return self();
        }

        @Nonnull
        public Builder recursive(boolean value) {
            recursive = value;

            return self();
        }

        @Nonnull
        public Builder withSizes(boolean value) {
            withSizes = value;

            return self();
        }

        @Nonnull
        @Override
        protected Builder self() {
            return this;
        }
    }
}
