def METHOD_NAME(
    permission: Union[Permission, ReferencePermission]
) -> LegacyPermission:
    """
    Return a legacy permission that corresponds to the provided new-style permission.
    If the provided permission is already a legacy style permission, it is returned.
    :param permission: a permission
    :return: the permission
    """
    if permission in (
        Permission.DELETE_SUBTRACTION,
        Permission.UPDATE_SUBTRACTION,
        Permission.CREATE_SUBTRACTION,
    ):
        return LegacyPermission.MODIFY_SUBTRACTION
    if permission == Permission.CREATE_UPLOAD:
        return LegacyPermission.UPLOAD_FILE
    if permission == Permission.DELETE_UPLOAD:
        return LegacyPermission.REMOVE_FILE
    if permission == Permission.CREATE_REFERENCE:
        return LegacyPermission.CREATE_REF
    raise ValueError(f"Unknown permission: {permission}")