//
// © 2018-2020 Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.
//

import UIKit
import MediaPlayer

class LocalMusicLibraryCacheCollection {
	let id: UInt64
	var items = [LocalMusicLibraryCacheItem]()
	var subCollections = [LocalMusicLibraryCacheCollection]() // Usually Albums if used.
	var representativeItem: LocalMusicLibraryCacheItem {
		return items.first! // There will always be at least one item
	}
	
	init(id: UInt64) {
		self.id = id
	}
}

// MARK: - Public Methods
extension LocalMusicLibraryCacheCollection {
	func toMusicLibraryArtist() -> MusicLibraryArtist {
		return MusicLibraryArtist(id: representativeItem.artistID,
								  representativeSongID: representativeItem.id,
								  name: representativeItem.artist,
								  numberOfAlbums: subCollections.count,
								  numberOfSongs: items.count)
	}
	
	func toMusicLibraryAlbum() -> MusicLibraryAlbum {
		return MusicLibraryAlbum(id: representativeItem.albumID,
								 representativeSongID: representativeItem.id,
								 title: representativeItem.albumTitle,
								 artist: representativeItem.artist,
								 numberOfSongs: items.count)
		
	}
	
	func toMusicLibraryGenre() -> MusicLibraryGenre {
		return MusicLibraryGenre(id: representativeItem.genreID,
								 representativeSongID: representativeItem.id,
								 name: representativeItem.genre,
								 numberOfAlbums: subCollections.count,
								 numberOfSongs: items.count)
		
	}
}
