ProductVO.java

/*
 * Copyright 2005-2025 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.openwms.wms.shipping.api;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import org.ameba.http.AbstractBase;

import java.beans.ConstructorProperties;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.StringJoiner;

/**
 * A ProductVO is the API representation of a {@code Product} in the Shipping Service.
 *
 * @author Heiko Scherrer
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ProductVO extends AbstractBase<ProductVO> implements Serializable {

    /** The persistent unique key. */
    @JsonProperty("pKey")
    private String pKey;
    /** The product id is part of the unique business key, must not be empty. */
    @NotBlank(message = "{owms.wms.shp.sku}", groups = ValidationGroups.Create.class)
    @JsonProperty("sku")
    private String sku;
    /** An identifying label of the Product. */
    @JsonIgnore // Ignore for now
    private String label;
    /** Textual descriptive text. */
    @JsonProperty("description")
    private String description;
    /** Arbitrary detail information on this product, might be by populated with ERP information. */
    @JsonProperty("details")
    private Map<String, String> details = new HashMap<>();

    /*~ -------------- constructors -------------- */
    public ProductVO() {}

    @ConstructorProperties({"sku"})
    public ProductVO(String sku) {
        this.sku = sku;
    }

    /*~ --------------- accessors ---------------- */
    public String getpKey() {
        return pKey;
    }

    public void setpKey(String pKey) {
        this.pKey = pKey;
    }

    public String getSku() {
        return sku;
    }

    public void setSku(String sku) {
        this.sku = sku;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Map<String, String> getDetails() {
        return details;
    }

    public void setDetails(Map<String, String> details) {
        this.details = details;
    }

    /*~ --------------- methods ---------------- */
    /**
     * {@inheritDoc}
     *
     * All fields.
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ProductVO)) return false;
        if (!super.equals(o)) return false;
        ProductVO productVO = (ProductVO) o;
        return Objects.equals(pKey, productVO.pKey) && Objects.equals(sku, productVO.sku) && Objects.equals(label, productVO.label) && Objects.equals(description, productVO.description) && Objects.equals(details, productVO.details);
    }

    /**
     * {@inheritDoc}
     *
     * All fields.
     */
    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), pKey, sku, label, description, details);
    }

    /**
     * {@inheritDoc}
     *
     * All fields.
     */
    @Override
    public String toString() {
        return new StringJoiner(", ", ProductVO.class.getSimpleName() + "[", "]")
                .add("pKey='" + pKey + "'")
                .add("sku='" + sku + "'")
                .add("label='" + label + "'")
                .add("description='" + description + "'")
                .add("details=" + details)
                .toString();
    }
}