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

public class SightConfigurationViewModel extends ViewModel {

    private final MutableLiveData<ISight> mSight;
    private final MutableLiveData<String> mManufacturer;
    private final MutableLiveData<String> mModel;
    private final MutableLiveData<Double> maV;
    private final MutableLiveData<Double> maH;
    private final MutableLiveData<String> mheVis;
    private final MutableLiveData<Double> mVertSkalaRangMin;
    private final MutableLiveData<Double> mVertSkalaRangMax;
    private final MutableLiveData<Double> mPointerOffset;


    public SightConfigurationViewModel() {
        this.mSight = new MutableLiveData<>();
        this.mManufacturer = new MutableLiveData<>();
        this.mModel = new MutableLiveData<>();
        this.maV = new MutableLiveData<>();
        this.maH = new MutableLiveData<>();
        this.mheVis = new MutableLiveData<>();
        this.mVertSkalaRangMin = new MutableLiveData<>();
        this.mVertSkalaRangMax = new MutableLiveData<>();
        this.mPointerOffset = new MutableLiveData<>();

        this.mSight.setValue(null);
        this.mManufacturer.setValue("");
        this.mModel.setValue("");
        this.maV.setValue(null);
        this.maH.setValue(null);
        this.mheVis.setValue("");
        this.mVertSkalaRangMin.setValue(null);
        this.mVertSkalaRangMax.setValue(null);
        this.mPointerOffset.setValue(null);
    }

    public void setSight(ISight aSight) {
        this.mSight.setValue(aSight);
        this.mManufacturer.setValue(aSight != null ? aSight.getManufacturer() : "");
        this.mModel.setValue(aSight != null ? aSight.getModel() : "");
        this.maV.setValue(aSight != null ? aSight.getAV() : null);
        this.maH.setValue(aSight != null ? aSight.getAH() : null);
        this.mheVis.setValue(aSight != null ? aSight.getHeVis() : "");
        this.mVertSkalaRangMin.setValue(aSight != null ? aSight.getVertSkalaRangeMin() : null);
        this.mVertSkalaRangMax.setValue(aSight != null ? aSight.getVertSkalaRangeMax() : null);
        this.mPointerOffset.setValue(aSight != null ? aSight.getPointerOffset() : null);
    }

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

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

    public void setAH(Double aH) {
        if (this.mSight.getValue() != null) {
            this.mSight.getValue().setAH(aH);
        }
        this.maH.setValue(aH);
    }

    public void setAV(Double aV) {
        if (this.mSight.getValue() != null) {
            this.mSight.getValue().setAV(aV);
        }
        this.maV.setValue(aV);
    }

    public void setHeVis(String heVis) {
        if (this.mSight.getValue() != null) {
            this.mSight.getValue().setHeVis(heVis);
        }
        this.mheVis.setValue(heVis);
    }

    public void setVertSkalaRangMin(Double aVertSkalaRangMin) {
        if (this.mSight.getValue() != null) {
            this.mSight.getValue().setVertSkalaRangeMin(aVertSkalaRangMin);
        }
        this.mVertSkalaRangMin.setValue(aVertSkalaRangMin);
    }

    public void setVertSkalaRangMax(Double aVertSkalaRangMax) {
        if (this.mSight.getValue() != null) {
            this.mSight.getValue().setVertSkalaRangeMax(aVertSkalaRangMax);
        }
        this.mVertSkalaRangMax.setValue(aVertSkalaRangMax);
    }

    public void setPointerOffset(Double aPointerOffset) {
        if (this.mSight.getValue() != null) {
            this.mSight.getValue().setPointerOffset(aPointerOffset);
        }
        this.mPointerOffset.setValue(aPointerOffset);
    }

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

    public LiveData<ISight> getRiser() {
        return mSight;
    }

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

    public LiveData<Double> getAV() {
        return maV;
    }

    public LiveData<Double> getAH() {
        return maH;
    }

    public LiveData<String> getHeVis() {
        return mheVis;
    }

    public LiveData<Double> getVertSkalaRangMin() {
        return mVertSkalaRangMin;
    }

    public LiveData<Double> getVertSkalaRangMax() {
        return mVertSkalaRangMax;
    }

    public LiveData<Double> getPointerOffset() {
        return mPointerOffset;
    }
}