/**
   * Attempts to update the specified project entry in the associated FreeAgent account.
   *
   * @param project The populated project instance.
   * @return True if the project has been updated successfully, otherwise false.
   */
  public boolean updateProject(FreeAgentProject project) {
    if (project != null) {
      String projectId = extractIdentifier(project.getUrl());

      if (projectId != null && !projectId.isEmpty()) {
        Response response =
            freeAgentServiceInstance.updateProject(new FreeAgentProjectWrapper(project), projectId);
        if (response.getStatus() == 200) {
          project.setUpdatedAt(dateFormat.format(new Date()));
          return true;
        } else {
          return false;
        }
      }
    }
    return false;
  }
  /**
   * Attempts to import a new project into the associated FreeAgent account by deserialising the
   * specified JSON project information and requesting a new project be created.
   *
   * <p>NOTE: The import (creation within FreeAgent) will only be actioned if no URL property is
   * present or if the URL property is not populated. Otherwise null will be returned.
   *
   * @param projectJSON A string containing project information in FreeAgent friendly format.
   * @return The newly populated project instance that has been imported into FreeAgent or null.
   * @throws JsonSyntaxException If the format does not match the FreeAgent V2 Project format.
   */
  public FreeAgentProject importProject(String projectJSON) throws JsonSyntaxException {
    if (projectJSON == null || projectJSON.isEmpty()) {
      return null;
    }

    FreeAgentProject project = buildProject(projectJSON);

    if (project != null && (project.getUrl() == null || project.getUrl().isEmpty())) {
      FreeAgentProjectWrapper projectWrapper =
          freeAgentServiceInstance.createProject(new FreeAgentProjectWrapper(project));

      if (projectWrapper != null) {
        return projectWrapper.getProject();
      }
    }

    return null;
  }
  /**
   * Retrieves the Contact associated with the specified project.
   *
   * @param project The populated project instance to retrieve the contact for.
   * @return A populated FreeAgentContact instance or null if the contact could not be found.
   */
  public FreeAgentContact getContactForProject(FreeAgentProject project) {
    if (project != null) {
      String contactId = extractIdentifier(project.getContact());

      if (contactId != null && !contactId.isEmpty()) {
        FreeAgentContactWrapper contactWrapper = freeAgentServiceInstance.getContact(contactId);

        if (contactWrapper != null) {
          return contactWrapper.getContact();
        }
      }
    }
    return null;
  }
  /**
   * Attempts to delete the specified project entry in the associated FreeAgent account.
   *
   * @param project The populated project instance.
   * @return True if the project has been deleted successfully, otherwise false.
   */
  public boolean deleteProject(FreeAgentProject project) {
    if (project != null) {
      String projectId = extractIdentifier(project.getUrl());

      if (projectId != null && !projectId.isEmpty()) {
        Response response = freeAgentServiceInstance.deleteProject(projectId);

        if (response.getStatus() == 200) {
          return true;
        } else {
          return false;
        }
      }
    }
    return false;
  }