/**
* Represents a product in the system.
*/
class Product {
/**
* Creates a new Product.
* @param {number} productId - Unique identifier for the product.
* @param {string} name - Name of the product.
* @param {number} categoryId - Associated category ID for the product.
* @param {number} price - Base price of the product.
* @param {string} imageUrl - URL of the product image.
* @param {string} [description=""] - Brief description of the product.
* @param {boolean} [isAvailable=true] - Availability status of the product.
* @param {boolean} [isSpecial=false] - Indicates if the product is a special item.
* @param {Array<Recipe>} [recipe=[]] - List of recipes associated with the product.
* @param {number} [preparationTime=0] - Time in minutes required to prepare the product.
* @param {number} [rank=0] - Rank of the product.
*/
constructor(productId, name, categoryId, price, imageUrl, description = "", isAvailable = true, isSpecial = false, recipe , rank = 0) {
this.productId = productId; // Unique identifier for the product
this.name = name; // Name of the product
this.categoryId = categoryId; // Associated category ID
this.price = price; // Base price of the product
this.imageUrl = imageUrl; // URL of the product image
this.description = description; // Brief description of the product
this.isAvailable = isAvailable; // Availability status
this.isSpecial = isSpecial; // Indicates if it's a special item
this.recipe = recipe; // Recipe details
this.rank = rank;//Rank of the product
this.createdAt = new Date();
this.updatedAt = new Date();
}
/**
* Updates the details of the product.
* @param {string} name - Updated name of the product.
* @param {number} categoryId - Updated category ID.
* @param {number} price - Updated price of the product.
* @param {string} imageUrl - Updated URL of the product image.
* @param {string} description - Updated description of the product.
* @param {boolean} isAvailable - Updated availability status.
* @param {boolean} isSpecial - Updated special status.
* @param {Array<Recipe>} recipe - Updated list of recipes.
* @param {number} preparationTime - Updated preparation time in minutes.
* @param {number} rank - Updated rank of the product.
*/
updateDetails(name, categoryId, price, imageUrl, description, isAvailable, isSpecial, recipe, preparationTime, rank) {
this.name = name;
this.categoryId = categoryId;
this.price = price;
this.imageUrl = imageUrl;
this.description = description;
this.isAvailable = isAvailable;
this.isSpecial = isSpecial;
this.recipe = recipe;
this.preparationTime = preparationTime;
this.rank = rank;
this.updatedAt = new Date();
}
/**
* Toggles the availability status of the product.
*/
toggleAvailability() {
this.isAvailable = !this.isAvailable;
this.updatedAt = new Date();
}
/**
* Calculates the final price of the product.
* @returns {number} - The final price of the product.
*/
getFinalPrice() {
return this.price;
}
}
module.exports = Product;