import os
from pathlib import Path
from urllib.parse import unquote

from dotenv import load_dotenv

load_dotenv()


def get_files(primary_key: dict[str, str]):
    fileserver = os.environ.get("LOCAL_STORAGE")
    files = [
        f.relative_to(fileserver)
        for f in Path(f"{fileserver}\\{primary_key['Client_DB']}\\{primary_key['Beleg_Nr']}").glob("*")
    ]
    return files


def get_file(name: str):
    fileserver = os.environ.get("LOCAL_STORAGE")
    filename = Path(f"{fileserver}\\{unquote(name)}")
    return filename
