# DO NOT EDIT THIS FILE!
#
# This file is generated from the CDP specification. If you need to make
# changes, edit the generator and regenerate all of the modules.
#
# CDP domain: CrashReportContext (experimental)

from __future__ import annotations
import typing
from dataclasses import dataclass
from .util import T_JSON_DICT
from . import page


@dataclass
class CrashReportContextEntry:
    """Key-value pair in CrashReportContext."""
    key: str
    value: str

    #: The ID of the frame where the key-value pair was set.
    frame_id: page.FrameId

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["key"] = self.key
        json["value"] = self.value
        json["frameId"] = self.frame_id.to_json()
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> CrashReportContextEntry:
        return cls(
            key=str(json["key"]),
            value=str(json["value"]),
            frame_id=page.FrameId.from_json(json["frameId"]),
        )


def get_entries() -> (
    typing.Generator[
        T_JSON_DICT,
        T_JSON_DICT,
        typing.List[CrashReportContextEntry],
    ]
):
    """
    Returns all entries in the CrashReportContext
    across all frames in the page.
    """
    cmd_dict: T_JSON_DICT = {
        "method": "CrashReportContext.getEntries",
    }
    json = yield cmd_dict
    return [CrashReportContextEntry.from_json(i) for i in json["entries"]]
