package com.mosquito.project.config;

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

import java.util.List;

@Configuration
@ConfigurationProperties(prefix = "app")
public class AppConfig {

    private SecurityConfig security = new SecurityConfig();
    private ShortLinkConfig shortLink = new ShortLinkConfig();
    private RateLimitConfig rateLimit = new RateLimitConfig();
    private CacheConfig cache = new CacheConfig();
    private PosterConfig poster = new PosterConfig();

    public static class SecurityConfig {
        private int apiKeyIterations = 185000;
        private String encryptionKey = "default-32-byte-key-for-dev-only!!";
        private IntrospectionConfig introspection = new IntrospectionConfig();

        public int getApiKeyIterations() { return apiKeyIterations; }
        public void setApiKeyIterations(int apiKeyIterations) { this.apiKeyIterations = apiKeyIterations; }
        public String getEncryptionKey() { return encryptionKey; }
        public void setEncryptionKey(String encryptionKey) { this.encryptionKey = encryptionKey; }
        public IntrospectionConfig getIntrospection() { return introspection; }
        public void setIntrospection(IntrospectionConfig introspection) { this.introspection = introspection; }
    }

    public static class IntrospectionConfig {
        private String url = "";
        private String clientId = "";
        private String clientSecret = "";
        private int timeoutMillis = 2000;
        private int cacheTtlSeconds = 60;
        private int negativeCacheSeconds = 5;

        public String getUrl() { return url; }
        public void setUrl(String url) { this.url = url; }
        public String getClientId() { return clientId; }
        public void setClientId(String clientId) { this.clientId = clientId; }
        public String getClientSecret() { return clientSecret; }
        public void setClientSecret(String clientSecret) { this.clientSecret = clientSecret; }
        public int getTimeoutMillis() { return timeoutMillis; }
        public void setTimeoutMillis(int timeoutMillis) { this.timeoutMillis = timeoutMillis; }
        public int getCacheTtlSeconds() { return cacheTtlSeconds; }
        public void setCacheTtlSeconds(int cacheTtlSeconds) { this.cacheTtlSeconds = cacheTtlSeconds; }
        public int getNegativeCacheSeconds() { return negativeCacheSeconds; }
        public void setNegativeCacheSeconds(int negativeCacheSeconds) { this.negativeCacheSeconds = negativeCacheSeconds; }
    }

    public static class ShortLinkConfig {
        private int codeLength = 8;
        private int maxUrlLength = 2048;
        private String landingBaseUrl = "https://example.com/landing";
        private String cdnBaseUrl = "https://cdn.example.com";

        public int getCodeLength() { return codeLength; }
        public void setCodeLength(int codeLength) { this.codeLength = codeLength; }
        public int getMaxUrlLength() { return maxUrlLength; }
        public void setMaxUrlLength(int maxUrlLength) { this.maxUrlLength = maxUrlLength; }
        public String getLandingBaseUrl() { return landingBaseUrl; }
        public void setLandingBaseUrl(String landingBaseUrl) { this.landingBaseUrl = landingBaseUrl; }
        public String getCdnBaseUrl() { return cdnBaseUrl; }
        public void setCdnBaseUrl(String cdnBaseUrl) { this.cdnBaseUrl = cdnBaseUrl; }
    }

    public static class RateLimitConfig {
        private int perMinute = 100;

        public int getPerMinute() { return perMinute; }
        public void setPerMinute(int perMinute) { this.perMinute = perMinute; }
    }

    public static class CacheConfig {
        private int leaderboardTtlMinutes = 5;
        private int activityTtlMinutes = 1;
        private int statsTtlMinutes = 2;
        private int graphTtlMinutes = 10;

        public int getLeaderboardTtlMinutes() { return leaderboardTtlMinutes; }
        public void setLeaderboardTtlMinutes(int leaderboardTtlMinutes) { this.leaderboardTtlMinutes = leaderboardTtlMinutes; }
        public int getActivityTtlMinutes() { return activityTtlMinutes; }
        public void setActivityTtlMinutes(int activityTtlMinutes) { this.activityTtlMinutes = activityTtlMinutes; }
        public int getStatsTtlMinutes() { return statsTtlMinutes; }
        public void setStatsTtlMinutes(int statsTtlMinutes) { this.statsTtlMinutes = statsTtlMinutes; }
        public int getGraphTtlMinutes() { return graphTtlMinutes; }
        public void setGraphTtlMinutes(int graphTtlMinutes) { this.graphTtlMinutes = graphTtlMinutes; }
    }

    public SecurityConfig getSecurity() { return security; }
    public void setSecurity(SecurityConfig security) { this.security = security; }
    public ShortLinkConfig getShortLink() { return shortLink; }
    public void setShortLink(ShortLinkConfig shortLink) { this.shortLink = shortLink; }
    public RateLimitConfig getRateLimit() { return rateLimit; }
    public void setRateLimit(RateLimitConfig rateLimit) { this.rateLimit = rateLimit; }
    public CacheConfig getCache() { return cache; }
    public void setCache(CacheConfig cache) { this.cache = cache; }
    public PosterConfig getPoster() { return poster; }
    public void setPoster(PosterConfig poster) { this.poster = poster; }
}
