import random
import string


def generate_csv_content(num_links):
    """Mock the contents of a Qualtrics unique link csv file.

    Args:
        num_links: int how many rows other than the header to generate

    Returns:
        a tuple with
        * the file contents as a string
        * a list of the unique link urls, in the same order as the csv rows
    """
    csv_rows = [
        '"Response ID","Last Name","First Name","External Data Reference","Email","Status","End Date","Link","Link Expiration"'
    ]
    # Based on unique link csv export as of 2017-02-21.
    link_row_template = (
        '"","","","","{rnd_str}@{rnd_str}.com","Email Not Sent Yet","",'
        '"{url}","2050-02-16 16:10:00"'
    )
    url_template = (
        'https://sshs.qualtrics.com/SE?'
        'Q_DL={rnd_str}_{rnd_str}_MLRP_{rnd_str}&Q_CHL=gl'
    )
    urls = []
    for x in range(num_links):
        rnd_str = ''.join(random.choice(string.ascii_lowercase)
                          for x in range(10))
        url = url_template.format(rnd_str=rnd_str)
        row_str = link_row_template.format(rnd_str=rnd_str, url=url)
        csv_rows.append(row_str)
        urls.append(url)
    content = "\n".join(csv_rows)
    return (content, urls)