from typing import Union
from typing import NoReturn
from typing import Mapping


def validate_embed_fields(fields: dict) -> Union[bool, NoReturn]:
    """Raises a ValueError if any of the given embed fields is invalid."""
    field_validators = ("name", "value", "inline")

    required_fields = ("name", "value")

    for field in fields:
        if len(field.get("name")) > 256:
            raise ValueError("Embed field-name length reached max limit.")
        if len(field.get("value")) > 1024:
            raise ValueError("Embed field-value length reached max limit.")
        if not isinstance((value := field.get("inline")), bool):
            raise ValueError(f"This field must be of type bool, not {type(value)}.")

        if not isinstance(field, Mapping):
            raise ValueError("Embed fields must be a mapping.")

        if not all(required_field in field for required_field in required_fields):
            raise ValueError(
                f"Embed fields must contain the following fields: {', '.join(required_fields)}."
            )

        for field_name in field:
            if field_name not in field_validators:
                raise ValueError(f"Unknown embed field field: {field_name!r}.")
    return True