class WorkspaceVariableImpl {

    @NotNull
    public static Map<String, Map<String, String>> createWorkspaceVariables(@NotNull TerraformWorkspaceVariableInputs terraformWorkspaceVariableInputs) throws Exception {
        String workspaceVariableName;
        String workspaceVariableValue;
        String hcl;
        String workspaceVariableCategory;
        Map<String, Map<String, String>> createWorkspaceVariableMap = new HashMap<>();
        JSONParser parser = new JSONParser();
        final HttpClientInputs httpClientInputs = new HttpClientInputs();
        final TerraformCommonInputs commonInputs = terraformWorkspaceVariableInputs.getCommonInputs();
        httpClientInputs.setUrl(createWorkspaceVariableUrl(terraformWorkspaceVariableInputs));
        setCommonHttpInputs(httpClientInputs, commonInputs);
        httpClientInputs.setAuthType(ANONYMOUS);
        httpClientInputs.setMethod(POST);
        httpClientInputs.setContentType(APPLICATION_VND_API_JSON);
        httpClientInputs.setHeaders(getAuthHeaders(commonInputs.getAuthToken()));
        if (!terraformWorkspaceVariableInputs.getWorkspaceVariableJson().isEmpty() & !terraformWorkspaceVariableInputs.getSensitiveWorkspaceVariableJson().isEmpty()) {
            String sensitiveWorkspaceVariableValue;

            JSONArray createWorkspaceVariableJsonArray = (JSONArray) parser.parse(terraformWorkspaceVariableInputs.getWorkspaceVariableJson());
            JSONArray createSensitiveWorkspaceVariableJsonArray = (JSONArray) parser.parse(terraformWorkspaceVariableInputs.getSensitiveWorkspaceVariableJson());
            JSONObject createWorkspaceVariableJson;
            JSONObject createSensitiveWorkspaceVariableJson;
            for (int i = 0; i < createWorkspaceVariableJsonArray.size(); i++) {
                createWorkspaceVariableJson = (JSONObject) createWorkspaceVariableJsonArray.get(i);
                workspaceVariableName = (String) createWorkspaceVariableJson.get("propertyName");
                workspaceVariableValue = (String) createWorkspaceVariableJson.get("propertyValue");
                hcl = Boolean.toString((boolean) createWorkspaceVariableJson.get("HCL"));
                workspaceVariableCategory = (String) createWorkspaceVariableJson.get("Category");


                terraformWorkspaceVariableInputs = terraformWorkspaceVariableInputs.builder()
                        .workspaceVariableName(workspaceVariableName)
                        .workspaceVariableValue(workspaceVariableValue)
                        .workspaceVariableCategory(workspaceVariableCategory)
                        .hcl(hcl)
                        .workspaceId(terraformWorkspaceVariableInputs.getWorkspaceId())
                        .sensitive("false").build();
                httpClientInputs.setBody(createWorkspaceVariableRequestBody(terraformWorkspaceVariableInputs));

                createWorkspaceVariableMap.put(workspaceVariableName, new HttpClientService().execute(httpClientInputs));

            }
            for (int i = 0; i < createSensitiveWorkspaceVariableJsonArray.size(); i++) {
                createSensitiveWorkspaceVariableJson = (JSONObject) createSensitiveWorkspaceVariableJsonArray.get(i);
                workspaceVariableName = (String) createSensitiveWorkspaceVariableJson.get("propertyName");
                sensitiveWorkspaceVariableValue = (String) createSensitiveWorkspaceVariableJson.get("propertyValue");
                hcl = Boolean.toString((boolean) createSensitiveWorkspaceVariableJson.get("HCL"));
                workspaceVariableCategory = (String) createSensitiveWorkspaceVariableJson.get("Category");


                terraformWorkspaceVariableInputs = terraformWorkspaceVariableInputs.builder()
                        .workspaceVariableName(workspaceVariableName)
                        .sensitiveWorkspaceVariableValue(sensitiveWorkspaceVariableValue)
                        .workspaceVariableValue(EMPTY)
                        .workspaceVariableCategory(workspaceVariableCategory)
                        .hcl(hcl)
                        .workspaceId(terraformWorkspaceVariableInputs.getWorkspaceId())
                        .sensitive("true").build();
                httpClientInputs.setBody(createWorkspaceVariableRequestBody(terraformWorkspaceVariableInputs));
                createWorkspaceVariableMap.put(workspaceVariableName, new HttpClientService().execute(httpClientInputs));

            }
            return createWorkspaceVariableMap;

        } else if (!terraformWorkspaceVariableInputs.getWorkspaceVariableJson().isEmpty()) {
            JSONArray createWorkspaceVariableJsonArray = (JSONArray) parser.parse(terraformWorkspaceVariableInputs.getWorkspaceVariableJson());
            JSONObject createWorkspaceVariableJson;
            for (int i = 0; i < createWorkspaceVariableJsonArray.size(); i++) {
                createWorkspaceVariableJson = (JSONObject) createWorkspaceVariableJsonArray.get(i);
                workspaceVariableName = (String) createWorkspaceVariableJson.get("propertyName");
                workspaceVariableValue = (String) createWorkspaceVariableJson.get("propertyValue");
                hcl = Boolean.toString((boolean) createWorkspaceVariableJson.get("HCL"));
                workspaceVariableCategory = (String) createWorkspaceVariableJson.get("Category");


                terraformWorkspaceVariableInputs = terraformWorkspaceVariableInputs.builder()
                        .workspaceVariableName(workspaceVariableName)
                        .workspaceVariableValue(workspaceVariableValue)
                        .workspaceVariableCategory(workspaceVariableCategory)
                        .hcl(hcl)
                        .workspaceId(terraformWorkspaceVariableInputs.getWorkspaceId())
                        .sensitive("false").build();
                httpClientInputs.setBody(createWorkspaceVariableRequestBody(terraformWorkspaceVariableInputs));
                createWorkspaceVariableMap.put(workspaceVariableName, new HttpClientService().execute(httpClientInputs));

            }

            return createWorkspaceVariableMap;
        } else {
            JSONArray createSensitiveWorkspaceVariableJsonArray = (JSONArray) parser.parse(terraformWorkspaceVariableInputs.getSensitiveWorkspaceVariableJson());
            JSONObject createSensitiveWorkspaceVariableJson;
            for (int i = 0; i < createSensitiveWorkspaceVariableJsonArray.size(); i++) {
                createSensitiveWorkspaceVariableJson = (JSONObject) createSensitiveWorkspaceVariableJsonArray.get(i);
                workspaceVariableName = (String) createSensitiveWorkspaceVariableJson.get("propertyName");
                workspaceVariableValue = (String) createSensitiveWorkspaceVariableJson.get("propertyValue");
                hcl = Boolean.toString((boolean) createSensitiveWorkspaceVariableJson.get("HCL"));
                workspaceVariableCategory = (String) createSensitiveWorkspaceVariableJson.get("Category");


                terraformWorkspaceVariableInputs = terraformWorkspaceVariableInputs.builder()

                        .workspaceVariableName(workspaceVariableName)
                        .sensitiveWorkspaceVariableValue(workspaceVariableValue)
                        .workspaceVariableValue(EMPTY)
                        .workspaceVariableCategory(workspaceVariableCategory)
                        .hcl(hcl)
                        .workspaceId(terraformWorkspaceVariableInputs.getWorkspaceId())
                        .sensitive("true").build();
                httpClientInputs.setBody(createWorkspaceVariableRequestBody(terraformWorkspaceVariableInputs));
                createWorkspaceVariableMap.put(workspaceVariableName, new HttpClientService().execute(httpClientInputs));

            }

            return createWorkspaceVariableMap;
        }


    }

}