package com.oguerreiro.resilient.service.dto;

import java.io.Serializable;
import java.util.Objects;

import com.oguerreiro.resilient.domain.User;

/**
 * A DTO representing a user, with only the public attributes.
 */
public class UserDTO implements Serializable {

  private static final long serialVersionUID = 1L;

  private Long id;

  private String login;

  private String email;

  public UserDTO() {
    // Empty constructor needed for Jackson.
  }

  public UserDTO(User user) {
    this.id = user.getId();
    this.login = user.getLogin();
    this.email = user.getEmail();
  }

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public String getLogin() {
    return login;
  }

  public void setLogin(String login) {
    this.login = login;
  }

  public String getEmail() {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    UserDTO userDTO = (UserDTO) o;
    if (userDTO.getId() == null || getId() == null) {
      return false;
    }

    return Objects.equals(getId(), userDTO.getId()) && Objects.equals(getLogin(), userDTO.getLogin());
  }

  // prettier-ignore
  @Override
  public String toString() {
    //@formatter:off
    return "UserDTO{" 
        + "id='" + id + '\'' 
        + ", login='" + login + '\''
        + ", email='" + email + '\'' 
        + "}";
    //@formatter:on
  }
}
