package com.storlead.sales.mail.connection.config;

import com.storlead.framework.common.util.encryptor.AccessKeyEncryptor;
import com.storlead.sales.mail.entity.SmtpPopSettingsEntity;
import lombok.Data;

/**
 * @program: sp-sales-platform
 * @description:
 * @author: chenkq
 * @create: 2024-05-30 16:59
 */
@Data
public class MailProperties {

    private String protocol;

    private String host;

    private String port;

    private String emailAddress;

    private String emailPassword;

    private Boolean tls;

    private Boolean ssl;


    public MailProperties(SmtpPopSettingsEntity smtpPop) {
        AccessKeyEncryptor accessKeyEncryptor = AccessKeyEncryptor.getAccessKeyEncryptor("");
        String pass = accessKeyEncryptor.decrypt(smtpPop.getEmailPassword());
        this.host = smtpPop.getReceiveServer() ;
        this.port = smtpPop.getReceivePort();
        this.emailAddress = smtpPop.getEmailAddress();
        this.emailPassword = pass;
        this.tls = Integer.valueOf(1).equals(smtpPop.getSmtpTls()) ? Boolean.TRUE : Boolean.FALSE;
        this.ssl = Integer.valueOf(1).equals(smtpPop.getSmtpSsl()) ? Boolean.TRUE : Boolean.FALSE;
        this.protocol = smtpPop.getProtocolType();
    }

}
