"use strict";

const Promise = require("bluebird");
const loadVideoFile = require("../load-video-file");
const elementToThumbnail = require("../element-to-thumbnail");

const { validateOptions } = require("@validatem/core");
const required = require("@validatem/required");
const isInteger = require("@validatem/is-integer");
const isString = require("@validatem/is-string");

module.exports = function thumbnailVideoBrowser(_options) {
	let { file, width, height, mimetype } = validateOptions(arguments, {
		file: [ required ], // FIXME
		maximumWidth: [ required, isInteger ], // FIXME: positive
		maximumHeight: [ required, isInteger ], // FIXME: positive
		mimetype: [ required, isString ]
	});

	return Promise.try(() => {
		return loadVideoFile(file);
	}).then((element) => {
		return elementToThumbnail({
			element: element,
			maximumWidth: width,
			maximumHeight: height,
			mimetype: mimetype
		});
	});
};
