import PropTypes from 'prop-types';
import MediaSegment from './MediaSegment';

export default class MediaObject {

	constructor(assetId, devientTranscriptId, mimeType, url, contentId, contentServerId, segments, resourceStart,
		resourceEnd, isRawContent, playoutAccess, duration=0) {
		this.assetId = assetId;
		this.devientTranscriptId = devientTranscriptId; //temporary fix
		this.mimeType = mimeType;
		this.url = url;

		this.contentId = contentId;
		this.contentServerId = contentServerId;

		this.segments = segments; //list of MediaSegment
		this.resourceStart = resourceStart;
		this.resourceEnd = resourceEnd;

		this.isRawContent = isRawContent;

		this.playoutAccess = playoutAccess;

		this.duration = duration;
	}

	static construct(obj, collectionConfig) {
		return new MediaObject(
			obj.assetId,
			obj.devientTranscriptId,
			obj.mimeType,
			obj.url,
			obj.contentId,
			obj.contentServerId,
			obj.segments, //curated segments
			obj.resourceStart, //on-air start time
			obj.resourceEnd, //on-air end time
			obj.isRawContent, //unedited material should not be made accessible (for current use cases)
			typeof(obj.playoutAccess) === 'boolean' ? obj.playoutAccess : collectionConfig.requiresPlayoutAccess()
		)
	}

	static getPropTypes(isRequired=false) {
		const mediaObjectShape = PropTypes.shape({
	    	url: PropTypes.string.isRequired,
	    	mimeType: PropTypes.string.isRequired,
	    	assetId: PropTypes.string.isRequired, // this should be a persistent ID

	    	contentId: PropTypes.string, // encoded asset ID for the content proxy
	    	contentServerId: PropTypes.string, // ID for the content proxy to decide which server to proxy

	    	segments: PropTypes.arrayOf(MediaSegment.getPropTypes()),
	    	resourceStart: PropTypes.number, // start (sec) of on-air content or related segment
	    	resourceEnd: PropTypes.number, // end (sec) of on-air content or related segment

	    	isRawContent : PropTypes.bool, // raw content is material used to created the main media object that reflects the (media) resource

	    	playoutAccess : PropTypes.bool, // if the user is allowed to watch the video
		});
		return isRequired ? mediaObjectShape.isRequired : mediaObjectShape;
	}

}