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

import java.util.List;

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

public class ArcherySetupConfigurationViewModel extends ViewModel {

    private List<ISight> allSights;
    private List<IRiser> allRisers;
    private List<IArrow> allArrows;

    private final MutableLiveData<IArcherySetup> mArcherySetup;
    private final MutableLiveData<String> mName;
    private final MutableLiveData<ISight> mSight;
    private final MutableLiveData<IRiser> mRiser;
    private final MutableLiveData<IArrow> mArrow;
    private final MutableLiveData<Double> mTargetCenterHeight;
    private final MutableLiveData<Double> mArrowNockHeight;
    private final MutableLiveData<Double> mBowPullout;
    private final MutableLiveData<Double> mHNA;
    private final MutableLiveData<Double> mDeltaTime;
    private final MutableLiveData<Double> mCalcPrecision;
    private final MutableLiveData<Double> mSightVertSkalaMiddle;
    private final MutableLiveData<Double> mSightHorzSetting;
    private final MutableLiveData<Double> mNockRaising;
    private final MutableLiveData<Double> mBraceHeight;


    public ArcherySetupConfigurationViewModel() {
        this.mArcherySetup = new MutableLiveData<>();
        this.mName = new MutableLiveData<>();
        this.mSight = new MutableLiveData<>();
        this.mRiser = new MutableLiveData<>();
        this.mArrow = new MutableLiveData<>();
        this.mTargetCenterHeight = new MutableLiveData<>();
        this.mArrowNockHeight = new MutableLiveData<>();
        this.mBowPullout = new MutableLiveData<>();
        this.mHNA = new MutableLiveData<>();
        this.mDeltaTime = new MutableLiveData<>();
        this.mCalcPrecision = new MutableLiveData<>();
        this.mSightVertSkalaMiddle = new MutableLiveData<>();
        this.mSightHorzSetting = new MutableLiveData<>();
        this.mNockRaising = new MutableLiveData<>();
        this.mBraceHeight = new MutableLiveData<>();

        this.mArcherySetup.setValue(null);
        this.mName.setValue("");
        this.mSight.setValue(null);
        this.mRiser.setValue(null);
        this.mArrow.setValue(null);
        this.mTargetCenterHeight.setValue(null);
        this.mArrowNockHeight.setValue(null);
        this.mBowPullout.setValue(null);
        this.mHNA.setValue(null);
        this.mDeltaTime.setValue(null);
        this.mCalcPrecision.setValue(null);
        this.mSightVertSkalaMiddle.setValue(null);
        this.mSightHorzSetting.setValue(null);
        this.mNockRaising.setValue(null);
        this.mBraceHeight.setValue(null);
    }

    public void setArcherySetup(IArcherySetup aArcherySetup) {
        this.mArcherySetup.setValue(aArcherySetup);
        this.mName.setValue(aArcherySetup != null ? aArcherySetup.getName() : "");
        this.mSight.setValue(aArcherySetup != null ? aArcherySetup.getSight() : null);
        this.mRiser.setValue(aArcherySetup != null ? aArcherySetup.getRiser() : null);
        this.mArrow.setValue(aArcherySetup != null ? aArcherySetup.getArrow() : null);
        this.mTargetCenterHeight.setValue(aArcherySetup != null ? aArcherySetup.getTargetCenterHeight() : null);
        this.mArrowNockHeight.setValue(aArcherySetup != null ? aArcherySetup.getArrowNockHeight() : null);
        this.mBowPullout.setValue(aArcherySetup != null ? aArcherySetup.getBowPullout() : null);
        this.mHNA.setValue(aArcherySetup != null ? aArcherySetup.getHNA() : null);
        this.mDeltaTime.setValue(aArcherySetup != null ? aArcherySetup.getDeltaTime() : null);
        this.mCalcPrecision.setValue(aArcherySetup != null ? aArcherySetup.getCalcPrecision() : null);
        this.mSightVertSkalaMiddle.setValue(aArcherySetup != null ? aArcherySetup.getSightVertSkalaMiddle() : null);
        this.mSightHorzSetting.setValue(aArcherySetup != null ? aArcherySetup.getSightHorzSetting() : null);
        this.mNockRaising.setValue(aArcherySetup != null ? aArcherySetup.getNockRaising() : null);
        this.mBraceHeight.setValue(aArcherySetup != null ? aArcherySetup.getBraceHeight() : null);
    }

    public void setName(String nameText) {
        if (this.mArcherySetup.getValue() != null) {
            this.mArcherySetup.getValue().setName(nameText);
        }
        this.mName.setValue(nameText);
    }

    public void setSight(ISight aSight) {
        if (this.mArcherySetup.getValue() != null) {
            this.mArcherySetup.getValue().setSight(aSight);
        }
        this.mSight.setValue(aSight);
    }

    public void setRiser(IRiser aRiser) {
        if (this.mArcherySetup.getValue() != null) {
            this.mArcherySetup.getValue().setRiser(aRiser);
        }
        this.mRiser.setValue(aRiser);
    }

    public void setArrow(IArrow aArrow) {
        if (this.mArcherySetup.getValue() != null) {
            this.mArcherySetup.getValue().setArrow(aArrow);
        }
        this.mArrow.setValue(aArrow);
    }

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

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

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

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

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

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

    public void setSightVertSkalaMiddle(Double mSightVertSkalaMiddle) {
        if (this.mArcherySetup.getValue() != null) {
            this.mArcherySetup.getValue().setSightVertSkalaMiddle(mSightVertSkalaMiddle);
        }
        this.mSightVertSkalaMiddle.setValue(mSightVertSkalaMiddle);
    }

    public void setSightHorzSetting(Double mSightHorzSetting) {
        if (this.mArcherySetup.getValue() != null) {
            this.mArcherySetup.getValue().setSightHorzSetting(mSightHorzSetting);
        }
        this.mSightHorzSetting.setValue(mSightHorzSetting);
    }

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

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

    public LiveData<IArcherySetup> getArcherySetup() {
        return mArcherySetup;
    }

    public LiveData<String> getName() {
        return mName;
    }

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

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

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

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

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

    public List<ISight> getAllSights() {
        return allSights;
    }

    public void setAllSights(List<ISight> allSights) {
        this.allSights = allSights;
    }

    public List<IRiser> getAllRisers() {
        return allRisers;
    }

    public void setAllRisers(List<IRiser> allRisers) {
        this.allRisers = allRisers;
    }

    public List<IArrow> getAllArrows() {
        return allArrows;
    }

    public void setAllArrows(List<IArrow> allArrows) {
        this.allArrows = allArrows;
    }

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

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

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

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

    public LiveData<Double> getSightVertSkalaMiddle() {
        return mSightVertSkalaMiddle;
    }

    public LiveData<Double> getSightHorzSetting() {
        return mSightHorzSetting;
    }

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

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

    public IRiser findRiserByName(String name) {
        for (IRiser riser : this.allRisers) {
            if (riser.toString().equals(name)) {
                return riser;
            }
        }
        return null;
    }

    public ISight findSightByName(String name) {
        for (ISight sight : this.allSights) {
            if (sight.toString().equals(name)) {
                return sight;
            }
        }
        return null;
    }

    public IArrow findArrowByName(String name) {
        for (IArrow arrow : this.allArrows) {
            if (arrow.toString().equals(name)) {
                return arrow;
            }
        }
        return null;
    }
}
