import os
from dotenv import load_dotenv
# import logging
import json

def load_config():
    """
    Loads configuration from environment variables.
    """

    # Load environment variables from .env file
    load_dotenv()

    # Define configuration dictionaries
    aws_config = {
        'aws_access_key_id': os.getenv('AWS_ACCESS_KEY_ID', ''),
        'aws_secret_access_key': os.getenv('AWS_SECRET_ACCESS_KEY', ''),
        'region_name': os.getenv('AWS_REGION', ''),
        'endpoint_url': os.getenv('AWS_ENDPOINT_URL', ''),
    }

    db_config = {
        'host': os.getenv('DB_HOST', ''),
        'database': os.getenv('DB_NAME', ''),
        'user': os.getenv('DB_USER', ''),
        'password': os.getenv('DB_PASSWORD', ''),
        'port': os.getenv('DB_PORT', ''),
    }

    ach_config = {
        'ach_editor_id': int(os.getenv('ACH_EDITOR_ID', '0')),
        'ach_approver_id': int(os.getenv('ACH_APPROVER_ID', '0')),
        'ach_notes': os.getenv('ACH_NOTES', ''),
        'ach_storage_location': json.loads(os.getenv('ACH_STORAGE_LOCATION', '{}')),
        'ach_file_type': json.loads(os.getenv('ACH_FILE_TYPE', '{}')), # unused
    }

    # Define ach_variables dictionary - consider moving these values to a separate configuration file (e.g., ach_variables.json)
    ach_variables = {
        'custom_data_in': {},
        'disk_size': 0,
        'media_disk_size': 0,
        'pdf_disk_size': 0,
        'extension': '.',
        'conservative_copy_extension': '.',
        'file_fullpath': '',
        'objectKeys': {
            'media': None,
            'pdf': None,
            'conservative_copy': None,
        },
        'inventory_code': '',
    }

    bucket_name = os.getenv('BUCKET_NAME', 'artchive-dev')

    # Load configurations from environment variables
    # (No need to create namedtuple instances here)

    # Log configuration loading status
    '''    logging.info(f'AWS config loaded: {aws_config}')
    logging.info(f'DB config loaded: {db_config}')
    logging.info(f'ACH config loaded: {ach_config}')
    logging.info(f'ACH variables loaded: {ach_variables}')
    logging.info(f'Bucket name loaded: {bucket_name}')'''

    return aws_config, db_config, ach_config, bucket_name, ach_variables

EXTENSION_MIME_MAP = {
    '.aif': 'audio/aiff',
    '.aiff': 'audio/aiff',
    '.avi': 'video/x-msvideo',
    '.jpg': 'image/jpeg',
    '.m4a': 'audio/mp4',
    '.m4v': 'video/mp4',
    '.mov': 'video/quicktime',
    '.mp3': 'audio/mpeg',
    '.mp4': 'video/mp4',
    '.mpg': 'video/mpeg',
    '.mxf': 'application/mxf',
    '.pdf': 'application/pdf',
    '.wav': 'audio/wav',
    '.wmv': 'video/x-ms-asf',
}

MIME_TYPES = sorted(list(set(EXTENSION_MIME_MAP.values())))


# Consider using a class for a more structured approach (optional)
