'''Essentials for the bot to function'''
import configparser
from os import environ, path

class ConfigError(Exception):
    '''Could not find config file'''

def get_config_file() -> str:
    '''Gets the path to the config file in the current environment'''
    env: str | None = environ.get('KEMOVERSE_ENV')
    if not env:
        raise ConfigError('Error: KEMOVERSE_ENV is unset')
    if not (env in ['prod', 'dev']):
        raise ConfigError(f'Error: Invalid environment: {env}')

    config_path: str = f'config_{env}.ini'

    if not path.isfile(config_path):
        raise ConfigError(f'Could not find {config_path}')
    return config_path

config = configparser.ConfigParser()
config.read(get_config_file())

# Username for the bot
USER     = config['credentials']['User'].lower()
# API key for the bot
KEY      = config['credentials']['Token']
# Bot's Misskey instance URL
INSTANCE = config['credentials']['Instance'].lower()

# TODO: move this to db
# Fedi handles in the traditional 'user@domain.tld' style, allows these users
# to use extra admin exclusive commands with the bot
ADMINS        = config['application']['DefaultAdmins']
# SQLite Database location
DB_PATH       = config['application']['DatabaseLocation']

NOTIFICATION_POLL_INTERVAL = int(config['notification']['PollInterval'])
NOTIFICATION_BATCH_SIZE    = int(config['notification']['BatchSize'])

GACHA_ROLL_INTERVAL = int(config['gacha']['RollInterval'])