MinimalTransportUnitVO.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.transport.api;

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

import java.io.Serializable;
import java.util.Objects;

/**
 * A MinimalTransportUnitVO.
 *
 * @author Heiko Scherrer
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class MinimalTransportUnitVO extends AbstractBase<MinimalTransportUnitVO> implements Serializable {

    /** The persistent key. */
    @JsonProperty("pKey")
    protected String pKey;

    /** The business key of the {@code TransportUnit}.*/
    @NotBlank(message = "{owms.wms.inv.tu.bk}", groups = ValidationGroups.CreateTransportUnit.class)
    @JsonProperty("transportUnitBK")
    protected String transportUnitBK;

    /*~-------------------- constructors --------------------*/
    @JsonCreator
    protected MinimalTransportUnitVO() {}

    public MinimalTransportUnitVO(@NotEmpty String transportUnitBK) {
        this.transportUnitBK = transportUnitBK;
    }

    private MinimalTransportUnitVO(MinimalTransportUnitBuilder builder) {
        transportUnitBK = builder.transportUnitBK;
    }

    public static MinimalTransportUnitBuilder minimalTransportUnitBuilder() {
        return new MinimalTransportUnitBuilder();
    }

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

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

    public String getTransportUnitBK() {
        return transportUnitBK;
    }

    public void setTransportUnitBK(String transportUnitBK) {
        this.transportUnitBK = transportUnitBK;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof MinimalTransportUnitVO)) return false;
        if (!super.equals(o)) return false;
        MinimalTransportUnitVO that = (MinimalTransportUnitVO) o;
        return Objects.equals(pKey, that.pKey) && Objects.equals(transportUnitBK, that.transportUnitBK);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), pKey, transportUnitBK);
    }

    /*~-------------------- Builder --------------------*/
    public static final class MinimalTransportUnitBuilder {
        private @NotEmpty String transportUnitBK;

        private MinimalTransportUnitBuilder() {}

        public MinimalTransportUnitBuilder transportUnitBK(@NotEmpty String val) {
            transportUnitBK = val;
            return this;
        }

        public MinimalTransportUnitVO build() {
            return new MinimalTransportUnitVO(this);
        }
    }
}