module IDRAC::Storage

def volumes(controller)

Get information about virtual disk volumes
def volumes(controller)
  raise Error, "Controller not provided" unless controller
  
  puts "Volumes (e.g. Arrays)".green
  
  v = controller["Volumes"]
  path = v["@odata.id"].split("v1/").last
  response = authenticated_request(:get, "/redfish/v1/#{path}?$expand=*($levels=1)")
  
  if response.status == 200
    begin
      data = JSON.parse(response.body)
      volumes = data["Members"].map do |vol|
        drives = vol["Links"]["Drives"]
        volume_data = { 
          name: vol["Name"], 
          capacity_bytes: vol["CapacityBytes"], 
          volume_type: vol["VolumeType"],
          drives: drives,
          write_cache_policy: vol.dig("Oem", "Dell", "DellVirtualDisk", "WriteCachePolicy"),
          read_cache_policy: vol.dig("Oem", "Dell", "DellVirtualDisk", "ReadCachePolicy"),
          stripe_size: vol.dig("Oem", "Dell", "DellVirtualDisk", "StripeSize"),
          raid_level: vol["RAIDType"],
          encrypted: vol["Encrypted"],
          lock_status: vol.dig("Oem", "Dell", "DellVirtualDisk", "LockStatus"),
          odata_id: vol["@odata.id"]
        }
        
        # Check FastPath settings
        volume_data[:fastpath] = fastpath_good?(vol)
        
        # Handle volume operations and status
        if vol["Operations"].any?
          volume_data[:health] = vol["Status"]["Health"] ? vol["Status"]["Health"] : "N/A"
          volume_data[:progress] = vol["Operations"].first["PercentageComplete"]
          volume_data[:message] = vol["Operations"].first["OperationName"]     
        elsif vol["Status"]["Health"] == "OK"
          volume_data[:health] = "OK"
          volume_data[:progress] = nil
          volume_data[:message] = nil
        else
          volume_data[:health] = "?"
          volume_data[:progress] = nil
          volume_data[:message] = nil
        end
        
        # Create the RecursiveOpenStruct after all properties are set
        RecursiveOpenStruct.new(volume_data, recurse_over_arrays: true)
      end
      
      return volumes.sort_by { |d| d.name }
    rescue JSON::ParserError
      raise Error, "Failed to parse volumes response: #{response.body}"
    end
  else
    raise Error, "Failed to get volumes. Status code: #{response.status}"
  end
end