package com.atlassian.bitbucket.internal.importer;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Optional;

import static org.apache.commons.lang3.StringUtils.stripToNull;

/**
 * Request for searching external repositories.
 */
public class ExternalRepositorySearchRequest extends ExternalRequest {

    private final Optional<String> filter;
    private final Optional<String> ownerName;

    private ExternalRepositorySearchRequest(@Nonnull Builder builder) {
        super(builder);
        filter = builder.filter;
        ownerName = builder.ownerName;
    }

    @Nonnull
    public Optional<String> getFilter() {
        return filter;
    }

    @Nonnull
    public Optional<String> getOwnerName() {
        return ownerName;
    }

    public static class Builder extends ExternalRequest.Builder {

        private Optional<String> filter = Optional.empty();
        private Optional<String> ownerName = Optional.empty();

        public Builder(@Nonnull Credential credential, @Nonnull ExternalSource source) {
            super(credential, source);
        }

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

        @Nonnull
        public Builder filter(@Nullable String value) {
            filter = Optional.ofNullable(stripToNull(value));
            return this;
        }

        @Nonnull
        public Builder ownerName(@Nullable String value) {
            ownerName = Optional.ofNullable(stripToNull(value));
            return this;
        }
    }
}
