// Path: library/src/main/java/com/pokegoapi/exceptions/request/InvalidCredentialsException.java
// public class InvalidCredentialsException extends RequestFailedException {
// 	public InvalidCredentialsException() {
// 		super();
// 	}
// 
// 	public InvalidCredentialsException(String reason) {
// 		super(reason);
// 	}
// 
// 	public InvalidCredentialsException(Throwable exception) {
// 		super(exception);
// 	}
// 
// 	public InvalidCredentialsException(String reason, Throwable exception) {
// 		super(reason, exception);
// 	}
// }


import POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo;
import com.pokegoapi.exceptions.request.InvalidCredentialsException;
import com.pokegoapi.exceptions.request.LoginFailedException;
import com.pokegoapi.util.SystemTimeImpl;
import com.pokegoapi.util.Time;
import com.squareup.moshi.Moshi;
import lombok.Setter;
import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.FormBody;
import okhttp3.FormBody.Builder;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/*
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.pokegoapi.auth;



public class PtcCredentialProvider extends CredentialProvider {
	public static final String CLIENT_SECRET = "w8ScCUXJQc6kXKw8FiOhd8Fixzht18Dq3PEVkUCP5ZPxtgyWsbTvWHFLm2wNY0JR";
	public static final String REDIRECT_URI = "https://www.nianticlabs.com/pokemongo/error";
	public static final String CLIENT_ID = "mobile-app_pokemon-go";
	public static final String SERVICE_URL = "https://sso.pokemon.com/sso/oauth2.0/callbackAuthorize";
	public static final String LOGIN_URL = "https://sso.pokemon.com/sso/login";
	public static final String LOGIN_OAUTH = "https://sso.pokemon.com/sso/oauth2.0/accessToken";
	public static final String USER_AGENT = "pokemongo/1 CFNetwork/897.1 Darwin/17.5.0"; //Lasted iOS 11.3.0
	//We try and refresh token 5 minutes before it actually expires
	protected static final long REFRESH_TOKEN_BUFFER_TIME = 5 * 60 * 1000;
	protected static final int MAXIMUM_RETRIES = 5;
	protected static final int[] UK2_VALUES = new int[]{2, 8, 21, 24, 28, 37, 56, 58, 59};

	protected final OkHttpClient client;
	protected final String username;
	protected final String password;
	protected final Time time;
	protected String tokenId;
	protected long expiresTimestamp;
	protected AuthInfo.Builder authbuilder;

	protected SecureRandom random = new SecureRandom();

	@Setter
	protected boolean shouldRetry = true;

	/**
	 * Instantiates a new Ptc login.
	 *
	 * @param client the client
	 * @param username Username
	 * @param password password
	 * @param time a Time implementation
	 * @throws LoginFailedException if an exception occurs while attempting to log in
	 * @throws InvalidCredentialsException if invalid credentials are used
	 */
	public PtcCredentialProvider(OkHttpClient client, String username, String password, Time time)
// Path: library/src/main/java/com/pokegoapi/exceptions/request/InvalidCredentialsException.java
// public class InvalidCredentialsException extends RequestFailedException {
// 	public InvalidCredentialsException() {
// 		super();
// 	}
// 
// 	public InvalidCredentialsException(String reason) {
// 		super(reason);
// 	}
// 
// 	public InvalidCredentialsException(Throwable exception) {
// 		super(exception);
// 	}
// 
// 	public InvalidCredentialsException(String reason, Throwable exception) {
// 		super(reason, exception);
// 	}
// }


// Path: library/src/main/java/com/pokegoapi/auth/PtcCredentialProvider.java
import POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo;
import com.pokegoapi.exceptions.request.InvalidCredentialsException;
import com.pokegoapi.exceptions.request.LoginFailedException;
import com.pokegoapi.util.SystemTimeImpl;
import com.pokegoapi.util.Time;
import com.squareup.moshi.Moshi;
import lombok.Setter;
import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.FormBody;
import okhttp3.FormBody.Builder;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/*
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.pokegoapi.auth;



public class PtcCredentialProvider extends CredentialProvider {
	public static final String CLIENT_SECRET = "w8ScCUXJQc6kXKw8FiOhd8Fixzht18Dq3PEVkUCP5ZPxtgyWsbTvWHFLm2wNY0JR";
	public static final String REDIRECT_URI = "https://www.nianticlabs.com/pokemongo/error";
	public static final String CLIENT_ID = "mobile-app_pokemon-go";
	public static final String SERVICE_URL = "https://sso.pokemon.com/sso/oauth2.0/callbackAuthorize";
	public static final String LOGIN_URL = "https://sso.pokemon.com/sso/login";
	public static final String LOGIN_OAUTH = "https://sso.pokemon.com/sso/oauth2.0/accessToken";
	public static final String USER_AGENT = "pokemongo/1 CFNetwork/897.1 Darwin/17.5.0"; //Lasted iOS 11.3.0
	//We try and refresh token 5 minutes before it actually expires
	protected static final long REFRESH_TOKEN_BUFFER_TIME = 5 * 60 * 1000;
	protected static final int MAXIMUM_RETRIES = 5;
	protected static final int[] UK2_VALUES = new int[]{2, 8, 21, 24, 28, 37, 56, 58, 59};

	protected final OkHttpClient client;
	protected final String username;
	protected final String password;
	protected final Time time;
	protected String tokenId;
	protected long expiresTimestamp;
	protected AuthInfo.Builder authbuilder;

	protected SecureRandom random = new SecureRandom();

	@Setter
	protected boolean shouldRetry = true;

	/**
	 * Instantiates a new Ptc login.
	 *
	 * @param client the client
	 * @param username Username
	 * @param password password
	 * @param time a Time implementation
	 * @throws LoginFailedException if an exception occurs while attempting to log in
	 * @throws InvalidCredentialsException if invalid credentials are used
	 */
	public PtcCredentialProvider(OkHttpClient client, String username, String password, Time time)
			throws LoginFailedException, InvalidCredentialsException {