package com.ffii.fpsms.modules.common

import com.ffii.fpsms.modules.settings.service.SettingsService
import org.apache.commons.lang3.StringUtils

open class MailSMTP(settingsService: SettingsService) {

    open var host: String? = null
    open var port: Int? = null
    open var username: String? = null
    open var password: String? = null
    open var auth: Boolean? = null

    init {
        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)
    }

    final override fun equals(other: Any?): Boolean {
        if (other == null || other !is MailSMTP) return false

        val o = other as MailSMTP
        if (StringUtils.equals(this.host, o.host) &&
            this.port == o.port &&
            StringUtils.equals(this.username, o.username) &&
            StringUtils.equals(this.password, o.password) &&
            this.auth == o.auth
        ) {
            return true
        }

        return false
    }
}