/*
 * Copyright (C) 2022 - Florindo Smilari (spherIC)
 */
package ch.spherIC.recurvebowsight.ui.configuration;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import ch.spherIC.recurvebowsight.model.IArrow;

public class ArrowConfigurationViewModel extends ViewModel {

    private final MutableLiveData<IArrow> mArrow;
    private final MutableLiveData<String> mManufacturer;
    private final MutableLiveData<String> mModel;
    private final MutableLiveData<Double> mDiameter;
    private final MutableLiveData<Double> mCW;
    private final MutableLiveData<Double> mWeight;
    private final MutableLiveData<Double> mV0;
    private final MutableLiveData<String> mColors;


    public ArrowConfigurationViewModel() {
        this.mArrow = new MutableLiveData<>();
        this.mManufacturer = new MutableLiveData<>();
        this.mModel = new MutableLiveData<>();
        this.mDiameter = new MutableLiveData<>();
        this.mCW = new MutableLiveData<>();
        this.mWeight = new MutableLiveData<>();
        this.mV0 = new MutableLiveData<>();
        this.mColors = new MutableLiveData<>();

        this.mArrow.setValue(null);
        this.mManufacturer.setValue("");
        this.mModel.setValue("");
        this.mDiameter.setValue(null);
        this.mCW.setValue(null);
        this.mWeight.setValue(null);
        this.mV0.setValue(null);
        this.mColors.setValue("");
    }

    public void setArrow(IArrow aArrow) {
        this.mArrow.setValue(aArrow);
        this.mManufacturer.setValue(aArrow != null ? aArrow.getManufacturer() : "");
        this.mModel.setValue(aArrow != null ? aArrow.getModel() : "");
        this.mDiameter.setValue(aArrow != null ? aArrow.getDiameter() : null);
        this.mCW.setValue(aArrow != null ? aArrow.getCw() : null);
        this.mWeight.setValue(aArrow != null ? aArrow.getWeight() : null);
        this.mV0.setValue(aArrow != null ? aArrow.getV0() : null);
        this.mColors.setValue(aArrow != null ? aArrow.getColors() : null);
    }

    public void setManufacturerText(String manufacturerText) {
        if (this.mArrow.getValue() != null) {
            this.mArrow.getValue().setManufacturer(manufacturerText);
        }
        this.mManufacturer.setValue(manufacturerText);
    }

    public void setModelText(String modelText) {
        if (this.mArrow.getValue() != null) {
            this.mArrow.getValue().setModel(modelText);
        }
        this.mModel.setValue(modelText);
    }

    public void setDiameter(Double aDiameter) {
        if (this.mArrow.getValue() != null) {
            this.mArrow.getValue().setDiameter(aDiameter);
        }
        this.mDiameter.setValue(aDiameter);
    }

    public void setCW(Double aCW) {
        if (this.mArrow.getValue() != null) {
            this.mArrow.getValue().setCw(aCW);
        }
        this.mCW.setValue(aCW);
    }

    public void setWeight(Double aWeight) {
        if (this.mArrow.getValue() != null) {
            this.mArrow.getValue().setWeight(aWeight);
        }
        this.mWeight.setValue(aWeight);
    }

    public void setV0(Double aV0) {
        if (this.mArrow.getValue() != null) {
            this.mArrow.getValue().setV0(aV0);
        }
        this.mV0.setValue(aV0);
    }

    public void setColors(String aColors) {
        if (this.mArrow.getValue() != null) {
            this.mArrow.getValue().setColors(aColors);
        }
        this.mColors.setValue(aColors);
    }

    public LiveData<IArrow> getArrow() {
        return mArrow;
    }

    public LiveData<String> getManufacturer() {
        return this.mManufacturer;
    }

    public LiveData<String> getModel() {
        return mModel;
    }

    public LiveData<Double> getDiameter() {
        return mDiameter;
    }

    public LiveData<Double> getCw() {
        return mCW;
    }

    public LiveData<Double> getWeight() {
        return mWeight;
    }

    public LiveData<Double> getV0() {
        return mV0;
    }

    public LiveData<String> getColors() {
        return mColors;
    }

}