2021-09-27 21:44:24 +02:00
|
|
|
package it.tdlight.client;
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
final class AuthenticationDataImpl implements AuthenticationData {
|
|
|
|
private final Long userPhoneNumber;
|
|
|
|
private final String botToken;
|
|
|
|
|
|
|
|
AuthenticationDataImpl(Long userPhoneNumber, String botToken) {
|
|
|
|
if ((userPhoneNumber == null) == (botToken == null)) {
|
|
|
|
throw new IllegalArgumentException("Please use either a bot token or a phone number");
|
|
|
|
}
|
|
|
|
if (botToken != null) {
|
|
|
|
if (botToken.length() < 5 || botToken.length() > 200) {
|
|
|
|
throw new IllegalArgumentException("Bot token is invalid: " + botToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.userPhoneNumber = userPhoneNumber;
|
|
|
|
this.botToken = botToken;
|
|
|
|
}
|
|
|
|
|
2021-09-27 22:15:17 +02:00
|
|
|
@Override
|
|
|
|
public boolean isQrCode() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-27 21:44:24 +02:00
|
|
|
@Override
|
|
|
|
public boolean isBot() {
|
|
|
|
return botToken != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getUserPhoneNumber() {
|
|
|
|
if (userPhoneNumber == null) {
|
|
|
|
throw new UnsupportedOperationException("This is not a user");
|
|
|
|
}
|
|
|
|
return userPhoneNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBotToken() {
|
|
|
|
if (botToken == null) {
|
|
|
|
throw new UnsupportedOperationException("This is not a bot");
|
|
|
|
}
|
|
|
|
return botToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
if (userPhoneNumber != null) {
|
|
|
|
return "+" + userPhoneNumber;
|
|
|
|
} else {
|
|
|
|
return "\"" + botToken + "\"";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (this == o) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (o == null || getClass() != o.getClass()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
AuthenticationDataImpl that = (AuthenticationDataImpl) o;
|
|
|
|
return Objects.equals(userPhoneNumber, that.userPhoneNumber) && Objects.equals(botToken, that.botToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return Objects.hash(userPhoneNumber, botToken);
|
|
|
|
}
|
|
|
|
}
|