import json


def generate_api_queries(input_container_sas_url,file_list_sas_urls,request_name_base,caller):
    """
    Generate .json-formatted API input from input parameters.  file_list_sas_urls is
    a list of SAS URLs to individual file lists (all relative to the same container).
    
    request_name_base is a request name for the set; if the base name is 'blah', individual
    requests will get request names of 'blah_chunk000', 'blah_chunk001', etc.
    
    Returns both strings and Python dicts
    
    return request_strings,request_dicts
    """
    
    assert isinstance(file_list_sas_urls,list)        

    request_dicts = []
    request_strings = []
    # i_url = 0; file_list_sas_url = file_list_sas_urls[0]
    for i_url,file_list_sas_url in enumerate(file_list_sas_urls):
        
        d = {}
        d['input_container_sas'] = input_container_sas_url
        d['images_requested_json_sas'] = file_list_sas_url
        if len(file_list_sas_urls) > 1:
            chunk_id = '_chunk{0:0>3d}'.format(i_url)
            request_name = request_name_base + chunk_id
        else:
            request_name = request_name_base
        d['request_name'] = request_name
        d['caller'] = caller
        request_dicts.append(d)
        request_strings.append(json.dumps(d,indent=1))
    
    return request_strings,request_dicts