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


def commit_draft(
    access_key: str,
    url: str,
    owner: str,
    dataset: str,
    *,
    draft_number: int,
    title: str,
    description: Optional[str] = None,
) -> Dict[str, str]:
    """Execute the OpenAPI `POST /v2/datasets/{owner}/{dataset}/commits`.

    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.
        draft_number: The draft number.
        title: The draft title.
        description: The draft description.

    Returns:
        The response of OpenAPI.

    Examples:
        >>> commit_draft(
        ...     "ACCESSKEY-********",
        ...     "https://api.graviti.com",
        ...     "czhual",
        ...     "MNIST",
        ...     draft_number=2,
        ...     title="commit-2",
        ... )
        {
           "commit_id": "85c57a7f03804ccc906632248dc8c359",
           "parent_commit_id": "784ba0d3bf0a41f6a7bfd771d8c00fcb",
           "title": "upload data",
           "description": "",
           "committer": "czhual",
           "committed_at": "2021-03-03T18:58:10Z"
        }

    """
    url = f"{url}/v2/datasets/{owner}/{dataset}/commits"
    post_data: Dict[str, Any] = {"draft_number": draft_number, "title": title}

    if description:
        post_data["description"] = description

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