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

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

public class CalculateSightParametersViewModel extends ViewModel {

    private final MutableLiveData<IArcherySetup> mSelectedArcherySetup;
    private final MutableLiveData<Double> mArrowDiameter;
    private final MutableLiveData<Double> mArrowCw;
    private final MutableLiveData<Double> mArrowWeight;
    private final MutableLiveData<Double> mBowPullout;
    private final MutableLiveData<Double> mArrowV0;
    private final MutableLiveData<Double> mHNA;
    private final MutableLiveData<Double> mNockRaising;
    private final MutableLiveData<Double> mBraceHeight;
    private final MutableLiveData<Double> mAirTemperature;
    private final MutableLiveData<Double> mRelativeAirHumidity;
    private final MutableLiveData<Double> mShootingDistance;
    private final MutableLiveData<Double> mArrowNockHeight;
    private final MutableLiveData<Double> mTargetCenterHeight;
    private final MutableLiveData<Double> mDeltaTime;
    private final MutableLiveData<Double> mCalcPrecision;

    public CalculateSightParametersViewModel() {
        this.mSelectedArcherySetup = new MutableLiveData<>();
        this.mArrowDiameter = new MutableLiveData<>();
        this.mArrowCw = new MutableLiveData<>();
        this.mArrowWeight = new MutableLiveData<>();
        this.mBowPullout = new MutableLiveData<>();
        this.mArrowV0 = new MutableLiveData<>();
        this.mHNA = new MutableLiveData<>();
        this.mNockRaising = new MutableLiveData<>();
        this.mBraceHeight = new MutableLiveData<>();
        this.mAirTemperature = new MutableLiveData<>();
        this.mRelativeAirHumidity = new MutableLiveData<>();
        this.mShootingDistance = new MutableLiveData<>();
        this.mArrowNockHeight = new MutableLiveData<>();
        this.mTargetCenterHeight = new MutableLiveData<>();
        this.mDeltaTime = new MutableLiveData<>();
        this.mCalcPrecision = new MutableLiveData<>();

        this.mArrowDiameter.setValue(null);
        this.mArrowCw.setValue(null);
        this.mArrowWeight.setValue(null);
        this.mBowPullout.setValue(null);
        this.mArrowV0.setValue(null);
        this.mHNA.setValue(null);
        this.mNockRaising.setValue(null);
        this.mBraceHeight.setValue(null);
        this.mAirTemperature.setValue(null);
        this.mRelativeAirHumidity.setValue(null);
        this.mShootingDistance.setValue(null);
        this.mArrowNockHeight.setValue(null);
        this.mTargetCenterHeight.setValue(null);
        this.mDeltaTime.setValue(null);
        this.mCalcPrecision.setValue(null);
    }

    public void setSelectedArcherySetup(IArcherySetup aSelectedArcherySetup) {
        this.mSelectedArcherySetup.setValue(aSelectedArcherySetup);
        this.mArrowDiameter.setValue(aSelectedArcherySetup != null ? aSelectedArcherySetup.getArrowDiameter() : null);
        this.mArrowCw.setValue(aSelectedArcherySetup != null ? aSelectedArcherySetup.getArrowCw() : null);
        this.mArrowWeight.setValue(aSelectedArcherySetup != null ? aSelectedArcherySetup.getArrowWeight() : null);
        this.mBowPullout.setValue(aSelectedArcherySetup != null ? aSelectedArcherySetup.getBowPullout() : null);
        this.mArrowV0.setValue(aSelectedArcherySetup != null ? aSelectedArcherySetup.getArrowV0() : null);
        this.mHNA.setValue(aSelectedArcherySetup != null ? aSelectedArcherySetup.getHNA() : null);
        this.mNockRaising.setValue(aSelectedArcherySetup != null ? aSelectedArcherySetup.getNockRaising() : null);
        this.mBraceHeight.setValue(aSelectedArcherySetup != null ? aSelectedArcherySetup.getBraceHeight() : null);
        this.mArrowNockHeight.setValue(aSelectedArcherySetup != null ? aSelectedArcherySetup.getArrowNockHeight() : null);
        this.mTargetCenterHeight.setValue(aSelectedArcherySetup != null ? aSelectedArcherySetup.getTargetCenterHeight() : null);
        this.mDeltaTime.setValue(aSelectedArcherySetup != null ? aSelectedArcherySetup.getDeltaTime() : null);
        this.mCalcPrecision.setValue(aSelectedArcherySetup != null ? aSelectedArcherySetup.getCalcPrecision() : null);
    }

    public void setArrowDiameter(Double aArrowDiameter) {
        if (this.mSelectedArcherySetup.getValue() != null) {
            this.mSelectedArcherySetup.getValue().setArrowDiameter(aArrowDiameter);
        }
        this.mArrowDiameter.setValue(aArrowDiameter);
    }

    public void setArrowCw(Double aArrowCw) {
        if (this.mSelectedArcherySetup.getValue() != null) {
            this.mSelectedArcherySetup.getValue().setArrowCw(aArrowCw);
        }
        this.mArrowCw.setValue(aArrowCw);
    }

    public void setArrowWeight(Double aArrowWeight) {
        if (this.mSelectedArcherySetup.getValue() != null) {
            this.mSelectedArcherySetup.getValue().setArrowWeight(aArrowWeight);
        }
        this.mArrowWeight.setValue(aArrowWeight);
    }

    public void setBowPullout(Double aBowPullout) {
        if (this.mSelectedArcherySetup.getValue() != null) {
            this.mSelectedArcherySetup.getValue().setBowPullout(aBowPullout);
        }
        this.mBowPullout.setValue(aBowPullout);
    }

    public void setArrowV0(Double aArrowV0) {
        if (this.mSelectedArcherySetup.getValue() != null) {
            this.mSelectedArcherySetup.getValue().setArrowV0(aArrowV0);
        }
        this.mArrowV0.setValue(aArrowV0);
    }

    public void setHNA(Double aHNA) {
        if (this.mSelectedArcherySetup.getValue() != null) {
            this.mSelectedArcherySetup.getValue().setHNA(aHNA);
        }
        this.mHNA.setValue(aHNA);
    }

    public void setNockRaising(Double aNockRaising) {
        if (this.mSelectedArcherySetup.getValue() != null) {
            this.mSelectedArcherySetup.getValue().setNockRaising(aNockRaising);
        }
        this.mNockRaising.setValue(aNockRaising);
    }

    public void setBraceHeight(Double aBraceHeight) {
        if (this.mSelectedArcherySetup.getValue() != null) {
            this.mSelectedArcherySetup.getValue().setBraceHeight(aBraceHeight);
        }
        this.mBraceHeight.setValue(aBraceHeight);
    }

    public void setAirTemperature(Double aAirTemperature) {
        this.mAirTemperature.setValue(aAirTemperature);
    }

    public void setRelativeAirHumidity(Double aRelativeAirHumidity) {
        this.mRelativeAirHumidity.setValue(aRelativeAirHumidity);
    }

    public void setShootingDistance(Double aShootingDistance) {
        this.mShootingDistance.setValue(aShootingDistance);
    }

    public void setArrowNockHeight(Double aArrowNockHeight) {
        if (this.mSelectedArcherySetup.getValue() != null) {
            this.mSelectedArcherySetup.getValue().setArrowNockHeight(aArrowNockHeight);
        }
        this.mArrowNockHeight.setValue(aArrowNockHeight);
    }

    public void setTargetCenterHeight(Double aTargetCenterHeight) {
        if (this.mSelectedArcherySetup.getValue() != null) {
            this.mSelectedArcherySetup.getValue().setTargetCenterHeight(aTargetCenterHeight);
        }
        this.mTargetCenterHeight.setValue(aTargetCenterHeight);
    }


    public void setDeltaTime(Double aDeltaTime) {
        if (this.mSelectedArcherySetup.getValue() != null) {
            this.mSelectedArcherySetup.getValue().setDeltaTime(aDeltaTime);
        }
        this.mDeltaTime.setValue(aDeltaTime);
    }

    public void setCalcPrecision(Double aCalcPrecision) {
        if (this.mSelectedArcherySetup.getValue() != null) {
            this.mSelectedArcherySetup.getValue().setCalcPrecision(aCalcPrecision);
        }
        this.mCalcPrecision.setValue(aCalcPrecision);
    }

    public IArcherySetup getSelectedArcherySetup() {
        return mSelectedArcherySetup.getValue();
    }

    public LiveData<Double> getArrowDiameter() {
        return this.mArrowDiameter;
    }

    public LiveData<Double> getArrowCw() {
        return this.mArrowCw;
    }

    public LiveData<Double> getArrowWeight() {
        return this.mArrowWeight;
    }

    public LiveData<Double> getBowPullout() {
        return this.mBowPullout;
    }

    public LiveData<Double> getArrowV0() {
        return this.mArrowV0;
    }

    public LiveData<Double> getHNA() {
        return this.mHNA;
    }

    public LiveData<Double> getNockRaising() {
        return this.mNockRaising;
    }

    public LiveData<Double> getBraceHeight() {
        return this.mBraceHeight;
    }

    public LiveData<Double> getAirTemperature() {
        return this.mAirTemperature;
    }

    public LiveData<Double> getRelativeAirHumidity() {
        return this.mRelativeAirHumidity;
    }

    public LiveData<Double> getShootingDistance() {
        return this.mShootingDistance;
    }

    public LiveData<Double> getArrowNockHeight() {
        return this.mArrowNockHeight;
    }

    public LiveData<Double> getTargetCenterHeight() {
        return this.mTargetCenterHeight;
    }

    public LiveData<Double> getDeltaTime() {
        return this.mDeltaTime;
    }

    public LiveData<Double> getCalcPrecision() {
        return this.mCalcPrecision;
    }

}