package com.cf.imes.module.system.framework.sms.core.property;

import com.cf.imes.framework.common.util.encrypt.AesUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

import jakarta.validation.constraints.NotEmpty;

/**
 * @author Gqr
 * @since 2024/8/23 10:51
 */
@ConfigurationProperties(prefix = "chenfeng.sms")
@Validated
public class SmsProperties {

    @Value("${chenfeng.encrypt.publicKey:}")
    private String publicKey;

    /**
     * 短信渠道
     */
    @NotEmpty(message = "短信渠道不能为空")
    private String channel;
    /**
     * 短信签名
     */
    private String signature;
    /**
     * 短信 API 的账号
     */
    @NotEmpty(message = "短信apiKey不能为空")
    private String apiKey;
    /**
     * 短信 API 的密钥
     */
    @NotEmpty(message = "短信apiSecret不能为空")
    private String apiSecret;

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public String getSignature() {
        return signature;
    }

    public SmsProperties setSignature(String signature) {
        this.signature = AesUtils.decrypt(signature, publicKey);
        return this;
    }

    public String getApiKey() {
        return apiKey;
    }


    public SmsProperties setApiKey(String apiKey) {
        this.apiKey = AesUtils.decrypt(apiKey, publicKey);
        return this;
    }

    public String getApiSecret() {
        return apiSecret;
    }

    public SmsProperties setApiSecret(String apiSecret) {
        this.apiSecret = AesUtils.decrypt(apiSecret, publicKey);
        return this;
    }
}
