import os
import sys
import ast
import random
import json
import product_gen.generate_product

from argparse import ArgumentParser

if __name__ == "__main__":
    
    argv = sys.argv
    argv = argv[argv.index("--") + 1:]
    shape_params = json.loads(argv[0])
    shape = shape_params['shape']
    output = shape_params['output']
    
    if not os.path.exists(os.getcwd() + "/" + output):
        os.makedirs(os.getcwd() + "/" + output)
    
    shape_parameters = {}
    shape_parameters["shape"] = shape
    shape_parameters["output"] = output
    shape_parameters["height"] = float(shape_params["height"])
    shape_parameters["radius"] = float(shape_params["radius"])
    shape_parameters["fixture_radius"] = float(shape_params["fixture_radius"])
    shape_parameters["division_offsets"] = [float(x) for x in shape_params["division_offsets"]]
    shape_parameters["style"] = shape_params["style"]
    shape_parameters["division_patterns"] = shape_params["division_patterns"]
    shape_parameters["division_radii"] = [float(x) for x in shape_params["division_radii"]]
    
    product_gen.generate_product.generate(shape_parameters, output)
    
    with open(os.getcwd() + "/" + output + "/"+ output + '.json', 'w') as outfile:
        json.dump(shape_parameters, outfile)
