package com.erp.task.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import lombok.Data;

/**
 * 告警配置
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "task.alert")
public class AlertConfig {

    /**
     * 是否启用告警
     */
    private boolean enabled = true;

    /**
     * 告警级别：INFO, WARN, ERROR
     */
    private String level = "ERROR";

    /**
     * 失败多少次后触发告警
     */
    private int alertAfterFailures = 1;

    /**
     * 告警静默时间（分钟）
     */
    private int silenceMinutes = 30;

    /**
     * 邮件告警
     */
    private EmailAlert email = new EmailAlert();

    /**
     * 短信告警
     */
    private SmsAlert sms = new SmsAlert();

    /**
     * WebHook告警
     */
    private WebHookAlert webhook = new WebHookAlert();

    @Data
    public static class EmailAlert {
        private boolean enabled = false;
        private String host;
        private int port = 25;
        private String username;
        private String password;
        private String from;
        private boolean useSsl = false;
    }

    @Data
    public static class SmsAlert {
        private boolean enabled = false;
        private String endpoint;
        private String apiKey;
    }

    @Data
    public static class WebHookAlert {
        private boolean enabled = false;
        private String url;
        private String secret;
    }
}
