package com.ycwl.basic.integration.common.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

@Data
@Component
@RefreshScope
@ConfigurationProperties(prefix = "integration")
public class IntegrationProperties {
    
    /**
     * 降级服务配置
     */
    private FallbackConfig fallback = new FallbackConfig();
    
    /**
     * 景区服务配置
     */
    private ScenicConfig scenic = new ScenicConfig();
    
    /**
     * 设备服务配置
     */
    private DeviceConfig device = new DeviceConfig();
    
    /**
     * 渲染工作器服务配置
     */
    private RenderWorkerConfig render = new RenderWorkerConfig();
    
    /**
     * 问卷服务配置
     */
    private QuestionnaireConfig questionnaire = new QuestionnaireConfig();
    
    @Data
    public static class ScenicConfig {
        /**
         * 是否启用景区服务集成
         */
        private boolean enabled = true;
        
        /**
         * 服务名称
         */
        private String serviceName = "zt-scenic";
        
        /**
         * 超时配置（毫秒）
         */
        private int connectTimeout = 5000;
        private int readTimeout = 10000;
        
        /**
         * 重试配置
         */
        private boolean retryEnabled = false;
        private int maxRetries = 3;
    }
    
    @Data
    public static class DeviceConfig {
        /**
         * 是否启用设备服务集成
         */
        private boolean enabled = true;
        
        /**
         * 服务名称
         */
        private String serviceName = "zt-device";
        
        /**
         * 超时配置（毫秒）
         */
        private int connectTimeout = 5000;
        private int readTimeout = 10000;
        
        /**
         * 重试配置
         */
        private boolean retryEnabled = false;
        private int maxRetries = 3;
    }
    
    @Data
    public static class FallbackConfig {
        /**
         * 是否启用降级功能
         */
        private boolean enabled = true;
        
        /**
         * 降级缓存前缀
         */
        private String cachePrefix = "integration:fallback:";
        
        /**
         * 默认降级缓存TTL（天）
         */
        private long defaultTtlDays = 1;
        
        /**
         * 服务特定的降级配置
         */
        private ServiceFallbackConfig scenic = new ServiceFallbackConfig();
        private ServiceFallbackConfig device = new ServiceFallbackConfig();
        private ServiceFallbackConfig render = new ServiceFallbackConfig();
        private ServiceFallbackConfig questionnaire = new ServiceFallbackConfig();
    }
    
    @Data
    public static class RenderWorkerConfig {
        /**
         * 是否启用渲染工作器服务集成
         */
        private boolean enabled = true;
        
        /**
         * 服务名称
         */
        private String serviceName = "zt-render-worker";
        
        /**
         * 超时配置（毫秒）
         */
        private int connectTimeout = 5000;
        private int readTimeout = 10000;
        
        /**
         * 重试配置
         */
        private boolean retryEnabled = false;
        private int maxRetries = 3;
    }
    
    @Data
    public static class QuestionnaireConfig {
        /**
         * 是否启用问卷服务集成
         */
        private boolean enabled = true;
        
        /**
         * 服务名称
         */
        private String serviceName = "zt-questionnaire";
        
        /**
         * 超时配置（毫秒）
         */
        private int connectTimeout = 5000;
        private int readTimeout = 10000;
        
        /**
         * 重试配置
         */
        private boolean retryEnabled = false;
        private int maxRetries = 3;
    }
    
    @Data
    public static class ServiceFallbackConfig {
        /**
         * 是否启用此服务的降级功能
         */
        private boolean enabled = true;
        
        /**
         * 服务特定的缓存TTL（天），如果为0则使用默认TTL
         */
        private long ttlDays = 0;
        
        /**
         * 服务特定的缓存前缀，如果为空则使用默认前缀
         */
        private String cachePrefix;
    }
}