from typing import Dict
from typing import OrderedDict


def compare_constraints(old_constraints: Dict, new_constraints: Dict) -> Dict:
    """Function to figure out which constraints are new and or deleted

    :param Dict old_constraints: The existing configuration
    :param Dict new_constraints: The new configuration

    :return: The altered constraints
    :rtype: Dict
    """

    # Set the pks
    old_pk = old_constraints.get('primary_key', {})
    new_pk = new_constraints.get('primary_key', {})

    # Set the change object
    pk_change = OrderedDict()

    # Calculate the delta
    if not new_pk and not old_pk:
        return pk_change
    elif old_pk and not new_pk:
        pk_change['drop_pk'] = old_pk
    elif new_pk and not old_pk:
        pk_change['new_pk'] = new_pk
    else:
        if new_pk['name'] != old_pk['name']:
            pk_change['drop_pk'] = old_pk
            pk_change['new_pk'] = new_pk
        elif new_pk['name'] != old_pk['name']:
            pk_change['drop_pk'] = old_pk
            pk_change['new_pk'] = new_pk

    return pk_change