/**
   * Returns a list of all the known projects contained within FreeAgent for the authorised account.
   *
   * @return A list of Project instances.
   */
  public List<FreeAgentProject> getProjects() {
    FreeAgentProjectWrapper projectsWrapper = freeAgentServiceInstance.getProjects();

    if (projectsWrapper != null) {
      return projectsWrapper.getProjects();
    }
    return null;
  }
  /**
   * Returns a list of all the known projects contained within FreeAgent for the authorised account.
   *
   * @param statusType The view type {@link
   *     com.karlnosworthy.freeagent.FreeAgentClient.ProjectStatusType} filter to apply to the
   *     projects.
   * @return A list of Project instances.
   */
  public List<FreeAgentProject> getProjects(ProjectStatusType statusType) {
    FreeAgentProjectWrapper projectsWrapper =
        freeAgentServiceInstance.getProjects(statusType.identifier);

    if (projectsWrapper != null) {
      return projectsWrapper.getProjects();
    }
    return null;
  }
 /**
  * Attempts to create a new project entry in the associated FreeAgent account.
  *
  * <p>Will return null if the project instance provided is null or cannot be saved into the
  * account.
  *
  * @param project The populated project instance.
  * @return The updated project instance or null.
  */
 public FreeAgentProject createProject(FreeAgentProject project) {
   if (project != null) {
     FreeAgentProjectWrapper projectWrapper =
         freeAgentServiceInstance.createProject(new FreeAgentProjectWrapper(project));
     if (projectWrapper != null) {
       return projectWrapper.getProject();
     }
   }
   return null;
 }
  /**
   * Retrieves the project that matches the specified id.
   *
   * @param projectId The id to match.
   * @return A Project instance or null if the id supplied was invalid or could not be matched.
   */
  public FreeAgentProject getProject(String projectId) {
    if (projectId != null && !projectId.isEmpty()) {
      FreeAgentProjectWrapper projectWrapper = freeAgentServiceInstance.getProject(projectId);

      if (projectWrapper != null) {
        return projectWrapper.getProject();
      }
    }
    return null;
  }
  /**
   * Returns a list of projects that are associated with the specified contact.
   *
   * @param contact The contact instance to look up projects for.
   * @return A list of the appropriate projects or null.
   */
  public List<FreeAgentProject> getProjects(FreeAgentContact contact) {
    if (contact != null && contact.getUrl() != null && !contact.getUrl().isEmpty()) {

      FreeAgentProjectWrapper projectsWrapper =
          freeAgentServiceInstance.getProjectsForContact(contact.getUrl());
      if (projectsWrapper != null) {
        return projectsWrapper.getProjects();
      }
    }
    return null;
  }
  /**
   * 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;
  }