package com.novoda.downloadmanager;

class InternalDownloadBatchStatusFixtures {

    private DownloadBatchTitle downloadBatchTitle = DownloadBatchTitleFixtures.aDownloadBatchTitle().build();
    private int percentageDownloaded = 10;
    private long bytesDownloaded = 100;
    private long bytesTotalSize = 1000;
    private DownloadBatchId downloadBatchId = DownloadBatchIdFixtures.aDownloadBatchId().build();
    private DownloadBatchStatus.Status status = DownloadBatchStatus.Status.QUEUED;
    private DownloadError.Type downloadErrorType = null;
    private long downloadedDateTimeInMillis = 123456789L;
    private boolean notificationSeen = false;

    static InternalDownloadBatchStatusFixtures anInternalDownloadsBatchStatus() {
        return new InternalDownloadBatchStatusFixtures();
    }

    InternalDownloadBatchStatusFixtures withDownloadBatchTitle(DownloadBatchTitle downloadBatchTitle) {
        this.downloadBatchTitle = downloadBatchTitle;
        return this;
    }

    InternalDownloadBatchStatusFixtures withPercentageDownloaded(int percentageDownloaded) {
        this.percentageDownloaded = percentageDownloaded;
        return this;
    }

    InternalDownloadBatchStatusFixtures withBytesDownloaded(long bytesDownloaded) {
        this.bytesDownloaded = bytesDownloaded;
        return this;
    }

    InternalDownloadBatchStatusFixtures withBytesTotalSize(long bytesTotalSize) {
        this.bytesTotalSize = bytesTotalSize;
        return this;
    }

    InternalDownloadBatchStatusFixtures withDownloadBatchId(DownloadBatchId downloadBatchId) {
        this.downloadBatchId = downloadBatchId;
        return this;
    }

    InternalDownloadBatchStatusFixtures withStatus(DownloadBatchStatus.Status status) {
        this.status = status;
        return this;
    }

    InternalDownloadBatchStatusFixtures withDownloadedDateTimeInMillis(long downloadedDateTimeInMillis) {
        this.downloadedDateTimeInMillis = downloadedDateTimeInMillis;
        return this;
    }

    InternalDownloadBatchStatusFixtures withDownloadErrorType(DownloadError.Type downloadErrorType) {
        this.downloadErrorType = downloadErrorType;
        return this;
    }

    InternalDownloadBatchStatusFixtures withNotificationSeen(boolean notificationSeen) {
        this.notificationSeen = notificationSeen;
        return this;
    }

    InternalDownloadBatchStatus build() {
        return new InternalDownloadBatchStatus() {

            @Override
            public DownloadBatchTitle getDownloadBatchTitle() {
                return downloadBatchTitle;
            }

            @Override
            public int percentageDownloaded() {
                return percentageDownloaded;
            }

            @Override
            public long bytesDownloaded() {
                return bytesDownloaded;
            }

            @Override
            public long bytesTotalSize() {
                return bytesTotalSize;
            }

            @Override
            public DownloadBatchId getDownloadBatchId() {
                return downloadBatchId;
            }

            @Override
            public Status status() {
                return status;
            }

            @Override
            public long downloadedDateTimeInMillis() {
                return downloadedDateTimeInMillis;
            }

            @Override
            public DownloadError downloadError() {
                return downloadErrorType;
            }

            @Override
            public void updateTotalSize(long totalBatchSizeBytes) {
                // do nothing.
            }

            @Override
            public void updateDownloaded(long currentBytesDownloaded) {
                // do nothing.
            }

            @Override
            public void markAsDownloading(DownloadsBatchStatusPersistence persistence) {
                status = Status.DOWNLOADING;
                persistence.updateStatusAsync(downloadBatchId, status);
            }

            @Override
            public void markAsPaused(DownloadsBatchStatusPersistence persistence) {
                status = Status.PAUSED;
                persistence.updateStatusAsync(downloadBatchId, status);
            }

            @Override
            public void markAsQueued(DownloadsBatchStatusPersistence persistence) {
                status = Status.QUEUED;
                persistence.updateStatusAsync(downloadBatchId, status);
            }

            @Override
            public void markAsDeleting() {
                status = Status.DELETING;
            }

            @Override
            public void markAsDeleted() {
                status = Status.DELETED;
            }

            @Override
            public void markAsError(Optional<DownloadError> downloadError, DownloadsBatchStatusPersistence persistence) {
                status = Status.ERROR;
                downloadErrorType = downloadError.get().type();
                persistence.updateStatusAsync(downloadBatchId, status);
            }

            @Override
            public void markAsDownloaded(DownloadsBatchStatusPersistence persistence) {
                status = Status.DOWNLOADED;
                persistence.updateStatusAsync(downloadBatchId, status);
            }

            @Override
            public void markAsWaitingForNetwork(DownloadsBatchPersistence persistence) {
                status = Status.WAITING_FOR_NETWORK;
                persistence.updateStatusAsync(downloadBatchId, status);
            }

            @Override
            public InternalDownloadBatchStatus copy() {
                return build();
            }

            @Override
            public boolean notificationSeen() {
                return notificationSeen;
            }
        };
    }
}

@@ -506,37 +506,32 @@
 te DownloadError
-.Type
  downloadErrorTy
@@ -528,20 +528,16 @@
 oadError
-Type
  = null;
@@ -2048,20 +2048,16 @@
 oadError
-Type
 (Downloa
@@ -2066,13 +2066,8 @@
 rror
-.Type
  dow
@@ -2076,20 +2076,16 @@
 oadError
-Type
 ) %7B%0A    
@@ -2098,36 +2098,32 @@
 is.downloadError
-Type
  = downloadError
@@ -2114,36 +2114,32 @@
  = downloadError
-Type
 ;%0A        return
@@ -3419,20 +3419,16 @@
 oadError
-Type
 ;%0A      
@@ -4862,16 +4862,57 @@
         
+InternalDownloadBatchStatusFixtures.this.
 download
@@ -4920,12 +4920,8 @@
 rror
-Type
  = d
@@ -4942,15 +4942,8 @@
 et()
-.type()
 ;%0A  

Update fixture.