/**
* Class representing LibreSignage user quota.
*
* @memberof module:libresignage/user
*/
class Quota {
	/**
	* Construct a Quota object.
	*
	* @param {object} data Quota data as received from the API.
	*/
	constructor(data) {
		this.limits = data.limits;
		this.used = data.used;
	}

	/**
	* Check whether there's quota left on a key.
	*
	* @param {string} key The key to check.
	* @param {number} amount The amount of quota required (default: 1)
	*
	* @return {boolean} True if there's enough quota left, false otherwise.
	*/
	has_quota(key, amount = 1) {
		return this.limits[key].limit - this.used[key] >= amount;
	}

	/**
	* Get all quota keys.
	*
	* @return {string[]} An array of quota keys.
	*/
	get_keys() { return Object.keys(this.limits); }

	/**
	* Get a quota limit.
	*
	* @param {string} key The quota key.
	*
	* @return {number} The corresponding limit.
	*/
	get_limit(key) { return this.limits[key].limit; }

	/**
	* Get the used quota on a key.
	*
	* @param {string} key The quota key.
	*
	* @return {number} The used quota.
	*/
	get_used(key) { return this.used[key]; }

	/**
	* Get the description of a quota.
	*
	* @param {string} key The quota key.
	*
	* @return {string} A string describing the quota.
	*/
	get_description(key) { return this.limits[key].description; }
}
module.exports = Quota;
