import os
from http.cookies import SimpleCookie

ROOT = os.path.abspath(os.path.dirname(__file__))


def get_file_path(name: str) -> str:
    return os.path.join(ROOT, name)


def read_file_path(name: str) -> str:
    with open(get_file_path(name)) as f:
        return f.read()


def parse_cookies(cookies: list[str] | None) -> dict[str, str]:
    parsed_cookies = {}

    if not cookies:
        return parsed_cookies

    for s in cookies:
        c = SimpleCookie()
        c.load(s)
        parsed_cookies.update({k: morsel.value for k, morsel in c.items()})

    return parsed_cookies
