#  Copyright (C) 2026
#  ABM, Moscow
#
#  UNPUBLISHED PROPRIETARY MATERIAL.
#  ALL RIGHTS RESERVED.
#
#  Authors: Mike Orlov <m.orlov@abm-jsc.ru>
import os
import pathlib

from .._toml import read_toml_file_by_path
from .._ini import read_ini_file_by_path


def read_file_as_dict(path: str | pathlib.Path | os.PathLike, encoding: str | None = None) -> dict[str, dict[str, str]]:
    prepared_path = pathlib.Path(path)
    extension = prepared_path.suffix
    if extension == '.toml':
        return read_toml_file_by_path(prepared_path, encoding=encoding)
    if extension == '.ini':
        return read_ini_file_by_path(prepared_path, encoding=encoding)
    raise TypeError(f'Unknown {extension=}')


def read_config(config_file_path: str) -> dict[str, dict[str, str]]:
    return read_file_as_dict(path=config_file_path)
