import json


def gen_location(service_name: str, service: dict, line_num: int):
    """
    Create a location directive from the service info and the sample
    :param service_name: name of the service (i.e. port)
    :param service: service json
    :param line_num: line num to start generation
    :return: finished location directive
    """
    with open("./sample_directive.json", 'r') as f:
        sample = json.load(f)
        try:
            sample["line"] = line_num
            sample["args"] = ["/" + service_name]
            port: str = service["expose"][0]
            sample["block"][0]["line"] = line_num + 1
            sample["block"][0]["args"] = ["http://" + service_name + ":" + port + "/"]
            return sample
        except KeyError:
            raise Exception("Expected value was missing from " + service_name + " service")