"use strict";

const sendMessageEvent = require("../send-message-event");
const unmapImageOptions = require("../unmap-image-options");

const { validateArguments } = require("@validatem/core");
const required = require("@validatem/required");
const optionalObject = require("../optional-object");
const isNonEmptyString = require("@validatem/is-non-empty-string");
const isInteger = require("@validatem/is-integer");
const isRoomID = require("../is-room-id");
const isThumbnailOptions = require("../is-thumbnail-options");
const isSession = require("@modular-matrix/is-session");
const isMXC = require("@modular-matrix/is-mxc-url");

module.exports = function sendStickerEvent(_session, _options) {
	let [ session, options ] = validateArguments(arguments, {
		session: [ required, isSession ],
		options: [ required, {
			roomID: [ required, isRoomID ],
			description: [ required, isNonEmptyString ],
			image: [ required, {
				url: [ required, isMXC ],
				displayWidth: [ isInteger ],
				displayHeight: [ isInteger ],
				mimetype: [ isNonEmptyString ],
				filesize: [ isInteger ],
			}],
			thumbnail: optionalObject(isThumbnailOptions)
		}]
	});

	return sendMessageEvent(session, {
		roomID: options.roomID,
		type: "m.sticker",
		content: unmapImageOptions(options)
	});
};
