tdlib-session-container/src/main/java/it/tdlight/reactiveapi/DiskSession.java

38 lines
1.0 KiB
Java
Raw Normal View History

2021-12-05 15:15:28 +01:00
package it.tdlight.reactiveapi;
2022-09-22 16:05:56 +02:00
import static it.tdlight.reactiveapi.Lanes.MAIN_LANE;
2021-12-05 15:15:28 +01:00
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
2022-09-22 15:46:31 +02:00
import java.util.Objects;
2021-12-05 15:15:28 +01:00
import org.jetbrains.annotations.Nullable;
@JsonInclude(Include.NON_NULL)
public class DiskSession {
@Nullable
public String token;
@Nullable
public Long phoneNumber;
2022-09-22 15:46:31 +02:00
@Nullable
public String lane;
2021-12-05 15:15:28 +01:00
@JsonCreator
2021-12-05 23:47:54 +01:00
public DiskSession(@JsonProperty("token") @Nullable String token,
2022-09-22 15:46:31 +02:00
@JsonProperty("phoneNumber") @Nullable Long phoneNumber,
@JsonProperty("lane") @Nullable String lane) {
2021-12-05 15:15:28 +01:00
this.token = token;
this.phoneNumber = phoneNumber;
2022-09-22 16:05:56 +02:00
this.lane = Objects.requireNonNullElse(lane, MAIN_LANE);
2021-12-05 15:15:28 +01:00
this.validate();
}
public void validate() {
if ((token == null) == (phoneNumber == null)) {
throw new UnsupportedOperationException("You must set either a token or a phone number");
}
}
}