from typing import List
from typing import Dict
from typing import Optional


def validate(schema: List[Dict],
             record: Dict,
             quiet: Optional[bool] = False) -> bool:
    """
    Validate a metadata record against a schema. This checks that the
    key names match and there aren't fewer or more keys than expected.

    Args:
        schema: the metadata schema to validate against
        record: metadata record to validate

    Returns:
        True if the metadata record is valid, False if it is not
    """
    # set keys from schema and record
    schema_keys = sorted([i["field_name"] for i in schema])
    record_keys = sorted(record.keys())

    # look for bad keys
    if (schema_keys != record_keys):
        if (quiet is False):
            print("Metadata invalid, keys don't match")
        return False

    # found no bad keys
    return True