from typing import Optional
from typing import Dict
from typing import Any


def update_dataset(
    access_key: str,
    url: str,
    owner: str,
    dataset: str,
    *,
    name: Optional[str] = None,
    alias: Optional[str] = None,
    default_branch: Optional[str] = None,
) -> Dict[str, Any]:
    """Execute the OpenAPI `PATCH /v2/datasets/{owner}/{dataset}`.

    Arguments:
        access_key: User's access key.
        url: The URL of the graviti website.
        owner: The owner of the dataset.
        dataset: Name of the dataset, unique for a user.
        name: New name of the dataset, unique for a user.
        alias: New alias of the dataset.
        default_branch: User's chosen branch.

    Returns:
        The response of OpenAPI.

    Examples:
        >>> update_dataset(
        ...     "ACCESSKEY-********",
        ...     "https://api.graviti.com",
        ...     "czhual",
        ...     "OxfordIIITPet",
        ...     name="OxfordIIITPets",
        ...     alias="Oxford-IIIT Pet",
        ...     default_branch="main",
        ... )
        {
           "id": "2bc95d506db2401b898067f1045d7f68",
           "name": "OxfordIIITPets",
           "alias": "Oxford-IIIT Pet",
           "default_branch": "main",
           "commit_id": "a0d4065872f245e4ad1d0d1186e3d397",
           "cover_url": "https://tutu.s3.cn-northwest-1.amazonaws.com.cn/",
           "created_at": "2021-03-03T18:58:10Z",
           "updated_at": "2021-03-04T18:58:10Z",
           "owner": "czhual",
           "is_public": false,
           "config": "exampleConfigName"
        }

    """
    url = f"{url}/v2/datasets/{owner}/{dataset}"
    patch_data: Dict[str, Any] = {}

    if name is not None:
        patch_data["name"] = name

    if alias is not None:
        patch_data["alias"] = alias

    if default_branch is not None:
        patch_data["default_branch"] = default_branch

    return open_api_do(  # type: ignore[no-any-return]
        "PATCH", access_key, url, json=patch_data
    ).json()