from pathlib import Path
import json
from typing import List


def is_asciicast(file_path: Path) -> bool:
    """
    is_asciicasts checks whether or not a file is an Asciinema recording
    by looking at the contents of the file's first line. In an asciicast
    v2 file, the first line should contain certain keys like "width",
    "height" and others.

    See: https://github.com/asciinema/asciinema/blob/develop/doc/asciicast-v2.md

    Args:
        file_path (Path): A path towards the file that will be checked.
    Returns:
        bool: Whether or not the file is an asciicast v2 file.
    """
    with open(file_path, "r") as stream:
        try:
            first_line: str = stream.readline()
        except Exception as err:
            return False

    try:
        parsed: dict = json.loads(first_line)
    except Exception as err:
        return False
    all_keys = parsed.keys()
    want: List[str] = ["version", "width", "height", "timestamp", "env"]

    for item in want:
        if item not in all_keys:
            return False

    if parsed["version"] != 2:
        return False

    return True