from typing import Sequence
from typing import Tuple
from typing import Set


def validate_given_deploy_groups(
    all_deploy_groups: Sequence[str], args_deploy_groups: Sequence[str]
) -> Tuple[Set[str], Set[str]]:
    """Given two lists of deploy groups, return the intersection and difference between them.

    :param all_deploy_groups: instances actually belonging to a service
    :param args_deploy_groups: the desired instances
    :returns: a tuple with (common, difference) indicating deploy groups common in both
        lists and those only in args_deploy_groups
    """
    invalid_deploy_groups: Set[str]
    if len(args_deploy_groups) == 0:
        valid_deploy_groups = set(all_deploy_groups)
        invalid_deploy_groups = set()
    else:
        valid_deploy_groups = set(args_deploy_groups).intersection(all_deploy_groups)
        invalid_deploy_groups = set(args_deploy_groups).difference(all_deploy_groups)

    return valid_deploy_groups, invalid_deploy_groups