from typing import Optional


def build_connection_uri_from_params(
    host: str,
    database: str,
    user: Optional[str],
    password: Optional[str],
    port: Optional[str],
) -> str:
    """Build the postgresql connection URI from the parameters

    Args:
        host (str): host of the database
        database (str): name of the database
        user (Optional[str]): user to access the database
        password (Optional[str]): password to access the database
        port (Optional[str]): port to access the database

    Returns:
        str: Connection URI
    """

    connection = "postgresql://"

    if user:
        auth = user

        if password:
            auth = f"{user}:{password}"

        connection += f"{auth}@"

    connection += host
    if port:
        connection += f":{port}"

    connection += f"/{database}"

    return connection