// This method will fetch all the child folders of the parent folder
        public void getChildFolders(String token, String folderId,int level)
        {
            String url = Resource.endpoint + "wittyparrot/api/folders/" + folderId + "/hierarchy/level/" + level ;
            var client = new RestClient();
            client.BaseUrl = new Uri(url);

            var request = new RestRequest();
            request.Method = Method.GET;
            request.Parameters.Clear();
            request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
            request.RequestFormat = DataFormat.Json;

            // execute the request
            IRestResponse response = client.Execute(request);
            String content = response.Content;

            if (response.ErrorException != null)
            {
                var statusMessage = RestUtils.getErrorMessage(response.StatusCode);
                MessageBox.Show(statusMessage == "" ? response.StatusDescription : statusMessage);
                var myException = new ApplicationException(response.StatusDescription, response.ErrorException);
                throw myException;
            }

            
            Folder parentfolder = JsonConvert.DeserializeObject<Folder>(content);
            List<Folder> childFolders = parentfolder.children;
            if (childFolders != null && childFolders.Count > 0)
            {
                foreach (var folder in childFolders)
                {
                    // save the folders into db

                    FolderDao folderDao = new FolderDao();
                    folderDao.saveFolder(folder);

                    WitsDao witsDao = new WitsDao();
                    RestClientWits restWits = new RestClientWits();


                    List<Wits> wits = restWits.getFolderWits(folder.id);
                    if (wits != null && wits.Count > 0)
                    {
                        witsDao.saveAllWits(wits);
                    }


                  
                    if (folder.hasChildren != null && folder.hasChildren == true)
                    {
                        // This is a self loop code where it check if a folder is having child folders
                        // loop itself get all the child folders and the wits of that folder
                        getChildFolders(token, folder.id, level);
                    }

                }
            }


        }
        // Fetch all the wits of the folder
        private void getFolderWitsThread(Folder folder)
        {
            RestClientWits restWits = new RestClientWits();
            WitsDao witsDao = new WitsDao();


            List<Wits> wits = restWits.getFolderWits(folder.id);
            if (wits != null && wits.Count > 0)
            {
                witsDao.saveAllWits(wits);
            }

        }