package synapticloop.b2.response;

/*
 * Copyright (c) 2016 iterate GmbH.
 *
 * All rights reserved.
 *
 * This code may contain contributions from other parties which, where
 * applicable, will be listed in the default build file for the project
 * ~and/or~ in a file named CONTRIBUTORS.txt in the root of the project.
 *
 * This source code and any derived binaries are covered by the terms and
 * conditions of the Licence agreement ("the Licence").  You may not use this
 * source code or any derived binaries except in compliance with the Licence.
 * A copy of the Licence is available in the file named LICENSE.txt shipped with
 * this source code or binaries.
 */

import org.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import synapticloop.b2.exception.B2ApiException;

import java.util.ArrayList;
import java.util.List;

public class B2ListPartsResponse extends BaseB2Response {
	private static final Logger LOGGER = LoggerFactory.getLogger(B2ListPartsResponse.class);

	private final String nextPartNumber;
	private final List<B2UploadPartResponse> files;

	public B2ListPartsResponse(String json) throws B2ApiException {
		super(json);

		this.nextPartNumber = this.readString(B2ResponseProperties.KEY_NEXT_FILE_ID);

		JSONArray filesArray = this.readObjects(B2ResponseProperties.KEY_PARTS);

		files = new ArrayList<B2UploadPartResponse>();
		for(int i = 0; i < filesArray.length(); i ++) {
			files.add(new B2UploadPartResponse(filesArray.optJSONObject(i)));
		}

		this.warnOnMissedKeys();
	}

	public String getNextPartNumber() {
		return nextPartNumber;
	}

	public List<B2UploadPartResponse> getFiles() {
		return files;
	}

	@Override
	protected Logger getLogger() { return LOGGER; }
}

@@ -1015,22 +1015,23 @@
 e final 
-String
+Integer
  nextPar
@@ -1203,22 +1203,19 @@
 his.read
-String
+Int
 (B2Respo
@@ -1378,16 +1378,17 @@
 );%0A%09%09for
+ 
 (int i =
@@ -1417,17 +1417,16 @@
 gth(); i
- 
 ++) %7B%0A%09%09
@@ -1536,22 +1536,23 @@
 %09public 
-String
+Integer
  getNext

Fix type of nextPartNumber.