class VariableImpl {

    @NotNull
    public static Map<String, Map<String, String>> createVariables(@NotNull TerraformVariableInputs terraformVariableInputs) throws Exception {
        String variableName;
        String variableValue;
        String hcl;
        String catagory;
        Map<String, Map<String, String>> createVariableMap = new HashMap<>();
        JSONParser parser = new JSONParser();
        final HttpClientInputs httpClientInputs = new HttpClientInputs();
        final TerraformCommonInputs commonInputs = terraformVariableInputs.getCommonInputs();
        httpClientInputs.setUrl(createVariableUrl());
        setCommonHttpInputs(httpClientInputs, commonInputs);
        httpClientInputs.setAuthType(ANONYMOUS);
        httpClientInputs.setMethod(POST);
        httpClientInputs.setContentType(APPLICATION_VND_API_JSON);
        httpClientInputs.setHeaders(getAuthHeaders(commonInputs.getAuthToken()));
        if (!terraformVariableInputs.getVariableJson().isEmpty() & !terraformVariableInputs.getSensitiveVariableJson().isEmpty()) {
            String sensitiveVariableValue;

            JSONArray createVariableJsonArray = (JSONArray) parser.parse(terraformVariableInputs.getVariableJson());
            JSONArray createSensitiveVariableJsonArray = (JSONArray) parser.parse(terraformVariableInputs.getSensitiveVariableJson());
            JSONObject createVariableJson;
            JSONObject createSensitiveVariableJson;
            for (int i = 0; i < createVariableJsonArray.size(); i++) {
                createVariableJson = (JSONObject) createVariableJsonArray.get(i);
                variableName = (String) createVariableJson.get("propertyName");
                variableValue = (String) createVariableJson.get("propertyValue");
                hcl = Boolean.toString((boolean) createVariableJson.get("HCL"));
                catagory = (String) createVariableJson.get("Category");

                terraformVariableInputs = TerraformVariableInputs.builder()
                        .variableName(variableName)
                        .variableValue(variableValue)
                        .variableCategory(catagory)
                        .hcl(hcl)
                        .workspaceId(terraformVariableInputs.getWorkspaceId())
                        .sensitive("false").build();
                httpClientInputs.setBody(createVariableRequestBody(terraformVariableInputs));
                createVariableMap.put(variableName, new HttpClientService().execute(httpClientInputs));

            }
            for (int i = 0; i < createSensitiveVariableJsonArray.size(); i++) {
                createSensitiveVariableJson = (JSONObject) createSensitiveVariableJsonArray.get(i);
                variableName = (String) createSensitiveVariableJson.get("propertyName");
                sensitiveVariableValue = (String) createSensitiveVariableJson.get("propertyValue");
                hcl = Boolean.toString((boolean) createSensitiveVariableJson.get("HCL"));
                catagory = (String) createSensitiveVariableJson.get("Category");

                terraformVariableInputs = TerraformVariableInputs.builder()
                        .variableName(variableName)
                        .sensitiveVariableValue(sensitiveVariableValue)
                        .variableValue(EMPTY)
                        .variableCategory(catagory)
                        .hcl(hcl)
                        .workspaceId(terraformVariableInputs.getWorkspaceId())
                        .sensitive("true").build();
                httpClientInputs.setBody(createVariableRequestBody(terraformVariableInputs));
                createVariableMap.put(variableName, new HttpClientService().execute(httpClientInputs));

            }
            return createVariableMap;

        } else if (!terraformVariableInputs.getVariableJson().isEmpty()) {
            JSONArray createVariableJsonArray = (JSONArray) parser.parse(terraformVariableInputs.getVariableJson());
            JSONObject createVariableJson;
            for (int i = 0; i < createVariableJsonArray.size(); i++) {
                createVariableJson = (JSONObject) createVariableJsonArray.get(i);
                variableName = (String) createVariableJson.get("propertyName");
                variableValue = (String) createVariableJson.get("propertyValue");
                hcl = Boolean.toString((boolean) createVariableJson.get("HCL"));
                catagory = (String) createVariableJson.get("Category");


                terraformVariableInputs = TerraformVariableInputs.builder()
                        .variableName(variableName)
                        .variableValue(variableValue)
                        .variableCategory(catagory)
                        .hcl(hcl)
                        .workspaceId(terraformVariableInputs.getWorkspaceId())
                        .sensitive("false").build();
                httpClientInputs.setBody(createVariableRequestBody(terraformVariableInputs));
                createVariableMap.put(variableName, new HttpClientService().execute(httpClientInputs));

            }

            return createVariableMap;
        } else {
            JSONArray createSensitiveVariableJsonArray = (JSONArray) parser.parse(terraformVariableInputs.getSensitiveVariableJson());
            JSONObject createSensitiveVariableJson;
            for (int i = 0; i < createSensitiveVariableJsonArray.size(); i++) {
                createSensitiveVariableJson = (JSONObject) createSensitiveVariableJsonArray.get(i);
                variableName = (String) createSensitiveVariableJson.get("propertyName");
                variableValue = (String) createSensitiveVariableJson.get("propertyValue");
                hcl = Boolean.toString((boolean) createSensitiveVariableJson.get("HCL"));
                catagory = (String) createSensitiveVariableJson.get("Category");

                terraformVariableInputs = TerraformVariableInputs.builder()

                        .variableName(variableName)
                        .sensitiveVariableValue(variableValue)
                        .variableValue(EMPTY)
                        .variableCategory(catagory)
                        .hcl(hcl)
                        .workspaceId(terraformVariableInputs.getWorkspaceId())
                        .sensitive("true").build();
                httpClientInputs.setBody(createVariableRequestBody(terraformVariableInputs));
                createVariableMap.put(variableName, new HttpClientService().execute(httpClientInputs));

            }

            return createVariableMap;
        }


    }

}