import logging


def get_source_and_destination_projects(conn, config):
    """

    :param conn:
    :param config:
    :return: the Source is a project the ignored alerts are pulled from and
             the Destination is a project where the alerts will be ignored.
             Default values:
                - destination project is a recent project of the certain product
                - source project is one before the recent (penultimate) project of the same product
    """
    logging.info('Getting all projects and sort them')
    all_projects = conn.get_projects()
    if len(all_projects) >= 2:
        all_projects.sort(key=lambda x: x['lastUpdatedDate'])
        logging.info('Find both recent (new) and penultimate projects')
        source_project = all_projects[-2]
        destination_project = all_projects[-1]
    else:
        raise ProcessLookupError("There are no enough projects in the product. Should be minimum 2.")

    return source_project, destination_project