package com.atlassian.bitbucket.mesh.client;

import com.atlassian.bitbucket.mesh.git.AbstractParameters;

import javax.annotation.Nonnull;
import java.util.concurrent.TimeUnit;

public class RepairRepositoryParameters extends AbstractParameters {

    private static final long DEFAULT_REPAIR_TIMEOUT_SECONDS = TimeUnit.HOURS.toSeconds(24L);

    private final boolean force;
    private final String repositoryId;
    private final boolean retryOnFailure;
    private final String sourceRepositoryId;

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

        force = builder.force;
        repositoryId = builder.repositoryId;
        retryOnFailure = builder.retryOnFailure;
        sourceRepositoryId = builder.sourceRepositoryId;
    }

    @Nonnull
    public String getRepositoryId() {
        return repositoryId;
    }

    @Nonnull
    public String getSourceRepositoryId() {
        return sourceRepositoryId;
    }

    public boolean isForce() {
        return force;
    }

    public boolean isRetryOnFailure() {
        return retryOnFailure;
    }

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

        private final String repositoryId;

        private boolean force;
        private boolean retryOnFailure;
        private String sourceRepositoryId;

        public Builder(@Nonnull String repositoryId) {
            this.repositoryId = requireNonBlank(repositoryId, "repositoryId");
            retryOnFailure = true;
            sourceRepositoryId = repositoryId;
            executionTimeout(DEFAULT_REPAIR_TIMEOUT_SECONDS);
        }

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

        @Nonnull
        public Builder force(boolean value) {
            force = value;
            return self();
        }

        @Nonnull
        public Builder retryOnFailure(boolean value) {
            retryOnFailure = value;
            return self();
        }

        @Nonnull
        public Builder sourceRepository(@Nonnull String value) {
            sourceRepositoryId = requireNonBlank(value, "sourceRepository");
            return self();
        }

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