@Override
    public ImportResult importItem(
            UUID jobId,
            IdempotentImportExecutor idempotentImportExecutor,
            TokensAndUrlAuthData authData,
            MusicContainerResource data)
            throws Exception {

        if (data == null) {
            // Nothing to do
            return new ImportResult(new AppleContentException("Null MusicContainerResource received on AppleMusicImporter::importItem"));
        }

        int playlistsCount = 0;
        int playlistItemsCount = 0;

        AppleMusicInterface musicInterface = factory
                .getOrCreateMusicInterface(jobId, authData, appCredentials, exportingService, monitor);

        if (!data.getPlaylists().isEmpty()) {
            playlistsCount = musicInterface.importPlaylists(jobId, idempotentImportExecutor, data.getPlaylists());
        }

        if (!data.getPlaylistItems().isEmpty()) {
            playlistItemsCount = musicInterface.importMusicPlaylistItems(jobId, idempotentImportExecutor, data.getPlaylistItems());
        }

        final Map<String, Integer> counts =
                new ImmutableMap.Builder<String, Integer>()
                        .put(AppleMusicConstants.PLAYLISTS_COUNT_DATA_NAME, playlistsCount)
                        .put(AppleMusicConstants.PLAYLIST_ITEMS_COUNT_DATA_NAME, playlistItemsCount)
                        .build();
        return ImportResult.OK
                .copyWithCounts(counts);
    }
@Test
    public void importPlaylistsFails() throws Exception {
        MusicPlaylist playlist1 = createTestMusicPlaylist();
        List<MusicPlaylist> musicPlaylists = List.of(playlist1);
        setUpImportPlaylistsBatchResponse(musicPlaylists.stream().collect(
                Collectors.toMap(MusicPlaylist::getId, playlist -> SC_BAD_REQUEST)));

        MusicContainerResource playlistsResource = new MusicContainerResource(musicPlaylists, null, null, null);
        final ImportResult importResult = appleMusicImporter.importItem(uuid, executor, authData, playlistsResource);

        verify(appleMusicInterface)
                .importPlaylistsBatch(uuid.toString(), musicPlaylists);

        assertThat(executor.getErrors()).hasSize(musicPlaylists.size());
        assertThat(importResult.getCounts().isPresent());
        ErrorDetail errorDetail = executor.getErrors().iterator().next();
        assertThat(errorDetail.id().equals(playlist1.getId()));
        assertThat(errorDetail.exception()).contains("Failed to create playlist");
    }