import CollectionConfig from './CollectionConfig';

export class EYEDesmetPapersConfig extends CollectionConfig {

	constructor(clientId, user, collectionId, stats, info) {
		super(clientId, user, collectionId, stats, info);
	}

	getCollectionMediaTypes() {
		return ['image']
	}

	//we want to search based on this granularity
	getFragmentPath() {
		return 'paper.*'
	}

	//this is the text field you can search on the line level
	getFragmentTextFields() {
		return ['paper.layer__ocr.text']
	}

	//includeMediaObjects() {
	//	return true;
	//}

	includeFragmentChildren() {
		return true
	}

	getMetadataFieldCategories() {
		return [
			{
				'id' : 'ocr',
				'label' : 'OCR',
				'nestedPath' : 'paper',
				'fields' : [
					'paper.layer__ocr.text'
				]
			},
			{
				'id' : 'titles',
				'label' : 'Titles',
				'fields' : [
					'folderTitle',
					'chapterName',
					'subChapterName'
				]
			}
		]
	}

	getFacets() {
		return [
			{
				field: 'Acteur.keyword',
				title : 'Acteur',
				id : 'acteur',
				type : 'string'
			}
		];
	}

	getItemDetailData(result, currentDateField) {
		result = this.formatSearchResult(result);
		const formattedResult = {}

		//then add the most basic top level data
		formattedResult.resourceId = result._id;
		formattedResult.index = result._index;
		formattedResult.docType = result._type;

		formattedResult.rawData = result;

		formattedResult.title = result.folderTitle;
		formattedResult.title += ' ' + result.chapterName;
		formattedResult.title += ' ' + result.subChapterName;

		formattedResult.description = result.groupCoverDescription;

		formattedResult.date = result.groupCoverPeriodRaw;
		formattedResult.dateField = 'groupCoverPeriodRaw';

		//formattedResult.posterURL = this.__getPoster(result);

		// const content = this.__extractPlayableContent(result);
		// if(content) {
		// 	formattedResult.playableContent = content.playableContent;
		// 	formattedResult.mediaTypes = content.mediaTypes;
		// }

		if(formattedResult.rawData.paper) {
			formattedResult.rawData.paper.forEach((p) => {
				delete p.layer__ocr;
			})
		}

		return formattedResult;
	}

	/* TODO implement this for EYE desmet paper (this was copy pasted from another config)
	__getPoster(result) {
		if (result['Url_efg_thumb']) {
			return result['Url_efg_thumb'];
		}
		return null;
	}

	__extractPlayableContent(result) {
		if(result['Url_efg_2'])	 {
			let playableContent = null;
			if(result['Url_efg_2'].indexOf('youtu') != -1) {
				playableContent = [{
					url : result['Url_efg_2'],
					mimeType : 'video/mp4',
					assetId : result._id
				}]
			} else {
				//for the external Flash player
				//https://api.picturepipe.net/api/3.0/playouttoken/488ac87e22ae48e5856a9eb29158bd3f/play
				playableContent = [{
					url : result['Url_efg_2'],
					mimeType : 'application/javascript',
					assetId : result._id
				}]
			}
			return {
				playableContent : playableContent,
				mediaTypes : ['video']
			}

		}
		return null;
	}*/

}

export default EYEDesmetPapersConfig;