/*
Copyright 2019 Dr. Thomas Benjamin Senior, Michael Zoeller 

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace EyeSkills
{
    public class BiocularObservables : MonoBehaviour
    {
        //Taken from Monocular Suppression Controller - I wish we had mixins.
        public MultiFixationSprite rightOccluder, leftOccluder;

        protected MultiFixationSprite currentOcculder;
        protected int fixIndex = 1;

        /// <summary>
        /// Which side to apply commands to. -1 is left, 0 is both, 1 is right.
        /// </summary>
        protected int applyCommandsToSide = 0;

        /// <summary>
        /// Hardcoded for two images. Just extend this to wrap around in sequence
        /// </summary>
        public void PickAlternateImage()
        {
            if (fixIndex == 1)
            {
                fixIndex = 0;
            }
            else
            {
                fixIndex = 1;
            }

            leftOccluder.PickByIndex(fixIndex);
            rightOccluder.PickByIndex(fixIndex);
        }

        public float AlterDistanceLeft(float startingDistance, bool v)
        {
            return leftOccluder.AlterDistance(startingDistance, v);
        }

        public float AlterDistanceRight(float startingDistance, bool v)
        {
            return rightOccluder.AlterDistance(startingDistance, v);
        }

        /// <summary>
        /// Alters the distance. Return value is potentially ambiguous.
        /// </summary>
        /// <returns>The distance.</returns>
        /// <param name="startingDistance">Starting distance.</param>
        /// <param name="v">If set to <c>true</c> v.</param>
        public float AlterDistance(float startingDistance, bool v)
        {
            float distance = 0;
            if (applyCommandsToSide == -1 || applyCommandsToSide == 0)
            {
                distance = AlterDistanceLeft(startingDistance, v);
            }

            if (applyCommandsToSide == 1 || applyCommandsToSide == 0)
            {
                distance = AlterDistanceRight(startingDistance, v);
            }

            return distance;
        }

        public void ApplyCommandsToLeftSide()
        {
            applyCommandsToSide = -1;
        }

        public void ApplyCommandsToRightSide()
        {
            applyCommandsToSide = 1;
        }

        public void ApplyCommandsToBothSides()
        {
            applyCommandsToSide = 0;
        }
    }
}