import os
from dotenv import load_dotenv

load_dotenv()

class Config:
    """Base configuration"""
    SECRET_KEY = os.getenv('SECRET_KEY', 'dev-secret-key-change-in-production')
    JWT_SECRET_KEY = os.getenv('JWT_SECRET_KEY', 'jwt-secret-key-change-in-production')
    
    # Rate Limiting untuk IP yang tidak terdaftar
    RATE_LIMIT_PER_DAY = int(os.getenv('RATE_LIMIT_PER_DAY', 20))
    RATE_LIMIT_WINDOW = int(os.getenv('RATE_LIMIT_WINDOW', 86400))  # 24 jam
    
    # IP Whitelist (unlimited access)
    # Pisahkan dengan koma, contoh: 127.0.0.1,192.168.1.1,::1
    IP_WHITELIST = [ip.strip() for ip in os.getenv('IP_WHITELIST', '127.0.0.1').split(',') if ip.strip()]
    
    # Swagger
    SWAGGER = {
        'title': 'Komiku API',
        'description': 'API for scraping Komiku.org comics data',
        'version': '1.0.0',
        'termsOfService': 'https://example.com/terms',
        'contact': {
            'name': 'API Support',
            'email': 'support@example.com'
        },
        'license': {
            'name': 'MIT',
            'url': 'https://opensource.org/licenses/MIT'
        }
    }
    
    # Komiku URLs
    KOMIKU_BASE_URL = 'https://komiku.org'
    KOMIKU_API_URL = 'https://api.komiku.org'
    KOMIKU_IMAGE_BASE = 'https://img.komiku.org'

class DevelopmentConfig(Config):
    DEBUG = True
    TESTING = False

class ProductionConfig(Config):
    DEBUG = False
    TESTING = False

class TestingConfig(Config):
    DEBUG = False
    TESTING = True

config_by_name = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
    'testing': TestingConfig,
    'default': DevelopmentConfig
}