package com.ssyf.third.bmiss.core;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;
import java.util.Map;

/**
 * 重试配置类
 */
@Data
@Accessors(chain = true)
public class RetryConfig {
    private boolean enabled = true;
    private int maxAttempts = 3;
    private double backoffFactor = 1.0;
    private List<Integer> retryStatusCodes;
    
    public RetryConfig() {
        this.retryStatusCodes = java.util.Arrays.asList(500, 502, 503, 504);
    }
    
    public RetryConfig(Map<String, Object> data) {
        this();
        this.enabled = (boolean) data.getOrDefault("enabled", true);
        this.maxAttempts = ((Number) data.getOrDefault("max_attempts", 3)).intValue();
        this.backoffFactor = ((Number) data.getOrDefault("backoff_factor", 1.0)).doubleValue();
        
        if (data.containsKey("retry_status_codes")) {
            this.retryStatusCodes = (List<Integer>) data.get("retry_status_codes");
        }
    }
}
