import warnings


def get_link_to_assembly(species_list):
    """
    Get the path for assembly download from NCBI

    Select the most up-to-date Complete Genome of the each organisms
    and returns the FTP path for that one.
    -----------------------------------------------------------------
    Argument:

    species_list--list of dictionary obtained from 
        get_entries_for_species function
    
    Return:
    link_assembly: str, FTP path to the genome assembly page of the 
        selected model:
        e.g ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/010/448/615/GCA_010448615.1_ASM1044861v1
    """
    
    genomes = []
    link_assembly = ''
    for i in species_list:
        if i['status'] == 'Complete Genome' and i['assembly'] not in ('', '-'):
            genomes.append(i)

    date_list = []
    if len(genomes) != 0:
        for i in genomes:
            if len(genomes) == 1:
                link_assembly += i['assembly']
            elif len(genomes) >1:
                date_list.append(i['date'])
    else: 
        # consider eliminating the options below: if there is no 
        # genomic information, there isn't any cds_from_genomic file
        warnings.warn('There is no complete genome for this species')

    if len(date_list) != 0:
        latest = max(date_list)
        for i in species_list:
            if i['date'] == latest:
                link_assembly += i['assembly']
                break # to pick the first match in case more than one entry have the same date
        
    
    return link_assembly