TransferBot/src/main/java/it/cavallium/UserStatus.java
2020-10-20 00:31:11 +02:00

100 lines
2.2 KiB
Java

package it.cavallium;
import java.util.StringJoiner;
import javafx.beans.property.SimpleStringProperty;
public class UserStatus {
private final String name;
private final int id;
private final UserStatusType statusType;
private final String errorDescription;
private final SimpleStringProperty user = new SimpleStringProperty("");
private final SimpleStringProperty status = new SimpleStringProperty("");
public UserStatus(String name, int id, UserStatusType statusType, String errorDescription) {
this.name = name;
this.id = id;
this.statusType = statusType;
this.errorDescription = errorDescription;
this.user.set(name);
this.status.set(errorDescription.isBlank() ? translateStatusType(statusType) : errorDescription);
}
private String translateStatusType(UserStatusType statusType) {
switch (statusType) {
case SCAM_USER:
return "Scam user, skipped";
case NO_ACCESS_HASH:
return "No access hash, skipped";
case RESTRICTED_USER:
return "User restricted, skipped";
case JUST_FOUND:
return "";
case UNKNOWN:
return "Unknown";
case NOT_REGULAR_USER:
return "Not a regular user, skipped";
default:
return statusType.toString();
}
}
public int getId() {
return id;
}
public String getErrorDescription() {
return errorDescription;
}
public String getName() {
return name;
}
public UserStatusType getStatusType() {
return statusType;
}
public String getUser() {
return user.get();
}
public String getStatus() {
return status.get();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
UserStatus that = (UserStatus) o;
if (id != that.id) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + id;
return result;
}
@Override
public String toString() {
return new StringJoiner(", ", UserStatus.class.getSimpleName() + "[", "]")
.add("name='" + name + "'")
.add("id=" + id)
.add("errorType=" + statusType)
.add("errorDescription='" + errorDescription + "'")
.toString();
}
}