package com.ffii.lioner.modules.common;

import org.apache.commons.lang3.StringUtils;

import com.ffii.lioner.modules.settings.service.SettingsService;

public class MailSMTP {
  private String host;
  private int port;
  private String username;
  private String password;
  private boolean auth;

  public MailSMTP(SettingsService settingsService) {
    if (settingsService == null)
      throw new IllegalArgumentException("settingsService");

    this.host = settingsService.getString(SettingNames.MAIL_SMTP_HOST);
    this.port = settingsService.getInt(SettingNames.MAIL_SMTP_PORT);
    this.username = settingsService.getString(SettingNames.MAIL_SMTP_USERNAME);
    this.password = settingsService.getString(SettingNames.MAIL_SMTP_PASSWORD);
    this.auth = settingsService.getBoolean(SettingNames.MAIL_SMTP_AUTH);
  }

  public String getHost() {
    return host;
  }

  public int getPort() {
    return port;
  }

  public String getUsername() {
    return username;
  }

  public String getPassword() {
    return password;
  }

  public boolean isAuth() {
    return this.auth;
  }

  public boolean getAuth() {
    return this.auth;
  }

  public void setAuth(boolean auth) {
    this.auth = auth;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null || !(obj instanceof MailSMTP))
      return false;

    MailSMTP o = (MailSMTP) obj;
    if (StringUtils.equals(this.getHost(), o.getHost()) &&
        this.getPort() == o.getPort() &&
        StringUtils.equals(this.getUsername(), o.getUsername()) &&
        StringUtils.equals(this.getPassword(), o.getPassword())) {
      return true;
    }

    return false;
  }

}
