package org.robolectric.shadows;

import static org.robolectric.util.ReflectionHelpers.ClassParameter.from;

import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.UserHandle;
import android.os.storage.StorageVolume;
import java.io.File;
import org.robolectric.util.ReflectionHelpers;

/** Class to build {@link StorageVolume} */
public final class StorageVolumeBuilder {

  private String id;
  private int storageId = 0;
  private File path;
  private String description;
  private boolean primary = true;
  private boolean removable = false;
  private boolean emulated = false;
  private long mtpReserveSize = 00L;
  private boolean allowMassStorage = false;
  private long maxFileSize = 100L;
  private UserHandle owner;
  private String fsUuid = "4213-3435:";
  private String state;

  public StorageVolumeBuilder(
      String id, File path, String description, UserHandle owner, String state) {
    this.id = id;
    this.path = path;
    this.description = description;
    this.owner = owner;
    this.state = state;
  }

  void setStorageId(int storageId) {
    this.storageId = storageId;
  }

  void setIsPrimary(boolean isPrimary) {
    this.primary = isPrimary;
  }

  void setIsRemovable(boolean isRemovable) {
    this.removable = isRemovable;
  }

  void setIsEmulated(boolean isEmulated) {
    this.emulated = isEmulated;
  }

  void setMtpReserveSize(long mtpReserveSize) {
    this.mtpReserveSize = mtpReserveSize;
  }

  void setAllowMassStorage(boolean allowMassStorage) {
    this.allowMassStorage = allowMassStorage;
  }

  void setMaxFileSize(long maxFileSize) {
    this.maxFileSize = maxFileSize;
  }

  public StorageVolume build() throws IllegalStateException {
    if (Build.VERSION.SDK_INT >= VERSION_CODES.N && Build.VERSION.SDK_INT < VERSION_CODES.P) {
      return ReflectionHelpers.callConstructor(
          StorageVolume.class,
          from(String.class, id), // String id,
          from(int.class, storageId), // int storageId
          from(File.class, path), // File path,
          from(String.class, description), // String description
          from(boolean.class, primary), // boolean primary,
          from(boolean.class, removable), // boolean removable,
          from(boolean.class, emulated), // boolean emulated,
          from(long.class, mtpReserveSize), //  long mtpReserveSize,
          from(boolean.class, allowMassStorage),
          from(long.class, maxFileSize), // long maxFileSize,
          from(UserHandle.class, owner), // UserHandle owner,
          from(String.class, fsUuid), //  String fsUuid,
          from(String.class, state)); // String state
    } else if (Build.VERSION.SDK_INT >= VERSION_CODES.P) {
      return ReflectionHelpers.callConstructor(
          StorageVolume.class,
          from(String.class, id), // String id,
          from(File.class, path), // File path,
          from(File.class, path), // File internalPath
          from(String.class, description), // String description
          from(boolean.class, primary), // boolean primary,
          from(boolean.class, removable), // boolean removable,
          from(boolean.class, emulated), // boolean emulated,
          from(boolean.class, allowMassStorage), //  boolean allowMassStorage,
          from(long.class, maxFileSize), // long maxFileSize,
          from(UserHandle.class, owner), // UserHandle owner,
          from(String.class, fsUuid), //  String fsUuid,
          from(String.class, state)); // String state
    }
    throw new IllegalStateException("StorageVolume hidden constructor not found");
  }
}

@@ -1046,32 +1046,39 @@
 = state;%0A  %7D%0A%0A  
+public 
 void setStorageI
@@ -1127,32 +1127,39 @@
 orageId;%0A  %7D%0A%0A  
+public 
 void setIsPrimar
@@ -1210,32 +1210,39 @@
 Primary;%0A  %7D%0A%0A  
+public 
 void setIsRemova
@@ -1301,32 +1301,39 @@
 movable;%0A  %7D%0A%0A  
+public 
 void setIsEmulat
@@ -1388,32 +1388,39 @@
 mulated;%0A  %7D%0A%0A  
+public 
 void setMtpReser
@@ -1490,32 +1490,39 @@
 rveSize;%0A  %7D%0A%0A  
+public 
 void setAllowMas
@@ -1611,16 +1611,23 @@
 %0A  %7D%0A%0A  
+public 
 void set

Make the set functions of StorageVolume builder public, so that it can be used.