package tv.pluto.mongo.entities.users;

import com.google.gson.annotations.JsonAdapter;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.BsonType;
import org.bson.codecs.pojo.annotations.BsonRepresentation;
import tv.pluto.mongo.utils.json.LocalDateTimeAdapter;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
  @BsonRepresentation(BsonType.OBJECT_ID)
  private String id;

  private String email;

  @JsonAdapter(LocalDateTimeAdapter.class)
  private LocalDateTime birthday;

  private String displayName;
  private String platformType;

  @JsonAdapter(LocalDateTimeAdapter.class)
  private LocalDateTime lastActive;

  @JsonAdapter(LocalDateTimeAdapter.class)
  private LocalDateTime dateCreated;

  private Name name;
  private Boolean acceptedTerms;
  private Integer loginAttempts;
  private String remoteAddress;

  public int getLoginAttempts() {
    return loginAttempts == null ? 0 : loginAttempts;
  }

  public String getDisplayName() {
    return displayName == null ? "" : displayName;
  }

  public String getPlatformType() {
    return platformType == null ? "" : platformType;
  }

  public String getRemoteAddress() {
    return remoteAddress == null ? "" : remoteAddress;
  }

  @Data
  @NoArgsConstructor
  @AllArgsConstructor
  public static class Name {
    private String givenName;

    public String getGivenName() {
      return givenName == null ? "" : givenName;
    }
  }
}
