from typing import List


def _parse_foreign_key_rule(rule: dict, name: str, key: List[str]) -> List[dict]:
    """Parse foreign key rule from resource descriptor.

    Args:
        meta: Resource descriptor.
        name: Resource name.
        key: Resource primary key.

    Returns:
        Parsed foreign key rules:

        * `fields` (List[str]): Local fields.
        * `reference['resource']` (str): Reference resource name.
        * `reference['fields']` (List[str]): Reference primary key fields.
        * `exclude` (List[str]): Names of resources to exclude, including `name`.
    """
    rules = []
    for fields in rule["fields"]:
        exclude = rule.get("exclude", [])
        rules.append(
            {
                "fields": fields,
                "reference": {"resource": name, "fields": key},
                "exclude": [name] + exclude,
            }
        )
    return rules