package com.atlassian.bitbucket.internal.importer.repository;

import com.atlassian.bitbucket.internal.importer.ExternalRequest;
import com.atlassian.bitbucket.internal.importer.Credential;
import com.atlassian.bitbucket.internal.importer.ExternalOwner;
import com.atlassian.bitbucket.internal.importer.ExternalSource;
import com.atlassian.bitbucket.project.Project;

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

import static java.util.Objects.requireNonNull;
import static java.util.Optional.empty;
import static java.util.Optional.ofNullable;

public class OwnerImportRequest extends ExternalRequest {

    private Optional<ExternalOwner> owner;
    private Project project;

    private OwnerImportRequest(@Nonnull Builder builder) {
        super(builder);

        owner = builder.owner;
        project = builder.project;
    }

    @Nonnull
    public Optional<ExternalOwner> getOwner() {
        return owner;
    }

    @Nonnull
    public Project getProject() {
        return project;
    }

    public static class Builder extends ExternalRequest.Builder {

        private Optional<ExternalOwner> owner = empty();
        private final Project project;

        public Builder(@Nonnull Credential credential, @Nonnull Project project, @Nonnull ExternalSource source) {
            super(credential, source);
            this.project = requireNonNull(project, "project");
        }

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

        @Nonnull
        public Builder owner(@Nullable ExternalOwner value) {
            owner = ofNullable(value);
            return this;
        }
    }
}
