from typing import Dict

from ttfrog.pwic.pwic import PwicConst as Config

from . import path


def init(config: Dict):
    Config.DB = path.CONFIG_ROOT
    Config.DB_SQLITE = Config.DB / "db.sql"
    Config.DB_SQLITE_BACKUP = Config.DB / "db_%s.sql"
    Config.DB_SQLITE_AUDIT = Config.DB / "db_audit.sql"
    Config.DOCUMENTS_PATH = Config.DB / "documents" / "%s"

    for key, value in config.items():
        if hasattr(Config, key):
            setattr(Config, key, value)
            continue
        if key.startswith("DB_DEFAULT_"):
            default_key = key.split("_", 2)[2]
            Config.DEFAULTS[default_key.lower()] = value

    return Config
