package com.social.media.domain.socialnetwork.valueobject;

import java.util.Map;

/**
 * Value Object representing API configuration for a social network
 */
public record ApiConfiguration(
    String apiEndpoint,
    String apiVersion,
    Map<String, Object> configurations,
    int rateLimitRequestsPerHour
) {
    
    public ApiConfiguration {
        if (rateLimitRequestsPerHour < 0) {
            throw new IllegalArgumentException("Rate limit cannot be negative");
        }
        configurations = configurations != null ? Map.copyOf(configurations) : Map.of();
    }
    
    public String getConfiguration(String key) {
        Object value = configurations.get(key);
        return value != null ? value.toString() : null;
    }
    
    public <T> T getConfiguration(String key, Class<T> type) {
        Object value = configurations.get(key);
        if (value != null && type.isInstance(value)) {
            return type.cast(value);
        }
        return null;
    }
    
    public boolean hasConfiguration(String key) {
        return configurations.containsKey(key);
    }
    
    public boolean hasRateLimit() {
        return rateLimitRequestsPerHour > 0;
    }
}
