+/*
+ * Copyright (C) 2016 - 2018 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jproduct.events.product.updated;
+
+import java.text.MessageFormat;
+import org.mxchange.jproduct.model.product.Product;
+
+/**
+ * An event fired when a new shop category has been updated.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class ProductUpdatedEvent implements UpdatedProductEvent {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 18_567_817_669_108L;
+
+ /**
+ * Product instance that has been updated
+ */
+ private final Product updatedProduct;
+
+ /**
+ * Constructor with updated product instance
+ * <p>
+ * @param updatedProduct Updated product
+ */
+ public ProductUpdatedEvent (final Product updatedProduct) {
+ // The category should be valid
+ if (null == updatedProduct) {
+ // Is NULL, throw NPE
+ throw new NullPointerException("updatedProduct is null"); //NOI18N
+ } else if (updatedProduct.getProductI18nKey().isEmpty()) {
+ // Empty title
+ throw new IllegalArgumentException("updatedProduct.productI18nKey is empty"); //NOI18N
+ } else if (updatedProduct.getProductId() == null) {
+ // Id is NULL
+ throw new NullPointerException("updatedProduct.productId is null"); //NOI18N
+ } else if (updatedProduct.getProductId() <= 0) {
+ // Not valid id
+ throw new IllegalArgumentException(MessageFormat.format("updatedProduct.productId={0} is not valid.", updatedProduct.getProductId())); //NOI18N
+ } else if (updatedProduct.getProductCategory() == null) {
+ // Id is NULL
+ throw new NullPointerException("updatedProduct.productCategory is null"); //NOI18N
+ } else if (updatedProduct.getProductCategory().getCategoryId() == null) {
+ // Id is NULL
+ throw new NullPointerException("updatedProduct.productCategory.categoryId is null"); //NOI18N
+ } else if (updatedProduct.getProductCategory().getCategoryId() <= 0) {
+ // Not valid id
+ throw new IllegalArgumentException(MessageFormat.format("updatedProduct.productCategory.categoryId={0} is not valid.", updatedProduct.getProductId())); //NOI18N
+ }
+
+ // Set it here
+ this.updatedProduct = updatedProduct;
+ }
+
+ @Override
+ public Product getUpdatedProduct () {
+ return this.updatedProduct;
+ }
+
+}