import CollectionConfig from './CollectionConfig';

export class EYEDesmetAfficheConfig extends CollectionConfig {

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

	getCollectionMediaTypes() {
		return ['image'];
	}

	getMetadataFieldCategories() {
		return [
			{
				'id' : 'titles',
				'label' : 'Titles',
				'fields' : [
					'Subtitels',
					'Affichetitel',
					'Filmwerk'
				]
			}
		]
	}

	getFacets() {
		return [
			{
				field: 'Land.keyword',
				title : 'Country',
				id : 'country',
				type : 'string'
			},
			{
				field: 'Drukker.keyword',
				title : 'Printer',
				id : 'printer',
				type : 'string'
			},
			{
				field: 'Beschadiging.keyword',
				title : 'Damage',
				id : 'damage',
				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 = this.__getTitle(result);
		formattedResult.description = this.__getDescription(result);
		formattedResult.date = result['Jaar'];
		formattedResult.dateField = 'Jaar';

		const content = this.__extractPlayableContent(result);
		if(content) {
			formattedResult.playableContent = content.playableContent;
			formattedResult.mediaTypes = content.mediaTypes;
		}
		formattedResult.externalSourceInfo = {
			url : null,
			message : "View in Eye's catalog: No direct link, use the \"ID\" to search in the EYE collectie catalogus: https://www.eyefilm.nl/eye-catalogus-zoek-in-de-collectie"
		}

		return formattedResult;
	}

	__getTitle(result) {
		if(result['Affichetitel']) {
			return result['Affichetitel'];
		}
		return 'Unknown'
	}

	__getDescription(result) {
		let desc = null;
		if(result['Subtitels']) {
			desc = result['Subtitels'];
		}
		if(result['Filmwerk']) {
			if(desc) {
				desc += ' (from the film: ' + result['Filmwerk'] + ')';
			} else {
				desc = 'From the film: ' + result['Filmwerk'];
			}
		}
		return desc ? desc : 'Unknown'
	}

	__extractPlayableContent(result) {
		if(result['ShownBy'] && result['ShownBy'] != '') {
			return {
				playableContent : [{
					url : result['ShownBy'],
					mimeType : 'image/jpeg',
					assetId : result._id,
					cors : false //prevents the use of OpenSeaDragon, which cannot load images without CORS
				}],
				mediaTypes : ['image']
			}
		}
	}

}

export default EYEDesmetAfficheConfig;