package com.atlassian.bitbucket.mesh.git;

import com.atlassian.bitbucket.mesh.io.ListenableWritableByteChannel;

import javax.annotation.Nonnull;
import java.io.IOException;

public interface UploadManager {

    /**
     * @param file describes the file the caller wants to upload
     * @return {@code true} if the file does not exist, or an outdated version of the file is present locally
     */
    boolean want(@Nonnull UploadFileParameters file);

    /**
     * Creates and returns a {@link ListenableWritableByteChannel} that can be used to (incrementally) write the
     * file contents to. The caller <em>MUST</em> {@link ListenableWritableByteChannel#close() close} the returned
     * {@link ListenableWritableByteChannel} to make the uploaded file visible.
     *
     * @param parameters describes the file the caller want to upload
     * @return an {@link ListenableWritableByteChannel} that can be used to write the file contents to
     * @throws IOException if an I/O error occurs while opening the {@link ListenableWritableByteChannel output}
     */
    @Nonnull
    ListenableWritableByteChannel uploadFile(@Nonnull UploadFileParameters parameters) throws IOException;
}
