import pathlib
import json


def input_data(file):
    """Read json instruction file to store record i.e. api details to the database."""
    # load in the instructions to add building outlines api from LINZ
    file_path = pathlib.Path().cwd() / pathlib.Path(file)
    with open(file_path, 'r') as file_pointer:
        instructions = json.load(file_pointer)
    instruction_node = instructions['instructions']
    source = instruction_node['source_name']
    region = instruction_node['region_name']
    geometry_column = instruction_node['geometry_col_name']
    url = instruction_node['url']
    api = instruction_node['api']
    data_provider = instruction_node['data_provider']
    layer = instruction_node['layer']
    record = {
        "source": source,
        "api": api,
        "url": url,
        "region": region,
        "layer": layer,
        "data_provider": data_provider,
        "geometry_column": geometry_column
    }
    return record