/*
 * 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.IRiser;

public class RiserConfigurationViewModel extends ViewModel {

    private final MutableLiveData<IRiser> mRiser;
    private final MutableLiveData<String> mManufacturer;
    private final MutableLiveData<String> mModel;
    private final MutableLiveData<Double> mSize;
    private final MutableLiveData<Double> mVVisH;
    private final MutableLiveData<Double> mVVisV;


    public RiserConfigurationViewModel() {
        this.mRiser = new MutableLiveData<>();
        this.mManufacturer = new MutableLiveData<>();
        this.mModel = new MutableLiveData<>();
        this.mSize = new MutableLiveData<>();
        this.mVVisH = new MutableLiveData<>();
        this.mVVisV = new MutableLiveData<>();

        this.mRiser.setValue(null);
        this.mManufacturer.setValue("");
        this.mModel.setValue("");
        this.mSize.setValue(null);
        this.mVVisH.setValue(null);
        this.mVVisV.setValue(null);
    }

    public void setRiser(IRiser aRiser) {
        this.mRiser.setValue(aRiser);
        this.mManufacturer.setValue(aRiser != null ? aRiser.getManufacturer() : "");
        this.mModel.setValue(aRiser != null ? aRiser.getModel() : "");
        this.mSize.setValue(aRiser != null ? aRiser.getSize() : null);
        this.mVVisH.setValue(aRiser != null ? aRiser.getVVisH() : null);
        this.mVVisV.setValue(aRiser != null ? aRiser.getVVisV() : null);
    }

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

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

    public void setSize(Double aSize) {
        if (this.mRiser.getValue() != null) {
            this.mRiser.getValue().setSize(aSize);
        }
        this.mSize.setValue(aSize);
    }

    public void setVVisH(Double aVVisH) {
        if (this.mRiser.getValue() != null) {
            this.mRiser.getValue().setVVisH(aVVisH);
        }
        this.mVVisH.setValue(aVVisH);
    }

    public void setVVisV(Double aVVisV) {
        if (this.mRiser.getValue() != null) {
            this.mRiser.getValue().setVVisV(aVVisV);
        }
        this.mVVisV.setValue(aVVisV);
    }

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

    public LiveData<IRiser> getRiser() {
        return mRiser;
    }

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

    public LiveData<Double> getSize() {
        return mSize;
    }

    public LiveData<Double> getVVisH() {
        return mVVisH;
    }

    public LiveData<Double> getVVisV() {
        return mVVisV;
    }
}