package it.integry.integrywmsnative.core.di;

import java.math.BigDecimal;
import java.math.RoundingMode;

import androidx.databinding.BaseObservable;

import it.integry.integrywmsnative.core.CommonConst;
import it.integry.integrywmsnative.core.utility.UtilityNumber;

public class BindableFloat extends BaseObservable {
    private Float value;

    public Float get() {
        return get(true);
    }

    public BigDecimal getBigDecimal() {
        int numberOfDigits = UtilityNumber.countNumberOfDecimalDigits(get());

        if(numberOfDigits > CommonConst.Config.NUMBER_OF_DECIMAL_DIGITS) numberOfDigits = CommonConst.Config.NUMBER_OF_DECIMAL_DIGITS;

        return new BigDecimal(get());
    }

    public Float get(boolean defaultIfNull) {

        if(value == null){
            if(defaultIfNull) return 0f;
            else return null;
        } else return value;
    }

    public void set(Float value) {
        if (!Objects.equals(this.value, value)) {
            this.value = value;
            notifyChange();
        }
    }

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

}
