
package dev.sonpx.loyalty.mcp.model.valueobject;

import lombok.Getter;
import lombok.ToString;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
 * Abstract generic class for value objects.
 * Provides automatic generation of getter, equals, hashCode, and toString methods
 * for the 'value' field using Lombok annotations.
 *
 * @param <T> the type of the value this class holds
 */
@Getter
@ToString
public abstract class BaseValue<T> {

    protected T value;

    /**
     * Constructs a new BaseValue object with the specified value.
     * @param value the value to set
     */
    public BaseValue(T value) {
        this.value = value;
    }

    public boolean isNull() {
        return value == null;
    }

    public boolean isNotNull() {
        return value != null;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (!(o instanceof BaseValue<?> baseValue)) return false;

        return new EqualsBuilder().append(getValue(), baseValue.getValue()).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37).append(getValue()).toHashCode();
    }
}
