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

public class GestureManager
{
    public static Gesture[] gestures;
    private static bool isInitialized = false;

    public static void InitializeArray()
    {
        if (isInitialized)
            return;

        isInitialized = true;

        #region Gesture List
        List<Gesture> gestureList = new List<Gesture>();

        Gesture punchFront = new Gesture(Gesture.GestureName.punch_front,
            new bool[] { false, false, false, false, false },
            new Vector3(1,0,0), new Vector3(0,0,1), new Vector3(1,0,0),
            new Gesture.GestureName[] { Gesture.GestureName.punch_front, Gesture.GestureName.paper, Gesture.GestureName.scissor });
        gestureList.Add(punchFront);

        Gesture punchUp = new Gesture(Gesture.GestureName.punch_up,
            new bool[] { false, false, false, false, false },
            new Vector3(0,1,0), new Vector3(0,0,1), new Vector3(1,1,0),
            new Gesture.GestureName[] { Gesture.GestureName.punch_down });
        gestureList.Add(punchUp);

        Gesture punchDown = new Gesture(Gesture.GestureName.punch_down,
            new bool[] { false, false, false, false, false },
            new Vector3(0,-1,0), new Vector3(0,0,1), new Vector3(1,-1,0),
            new Gesture.GestureName[] { Gesture.GestureName.punch_up });
        gestureList.Add(punchDown);

        Gesture hifive = new Gesture(Gesture.GestureName.hifive,
            new bool[] { true, true, true, true, true },
            new Vector3(1,0,0), new Vector3(1,0,0), new Vector3(0,1,0),
            new Gesture.GestureName[] { Gesture.GestureName.hifive });
        gestureList.Add(hifive);

        Gesture peace = new Gesture(Gesture.GestureName.peace,
            new bool[] { false, true, true, false, false },
            new Vector3(0,0,0), new Vector3(1,0,0), new Vector3(0,1,0),
            new Gesture.GestureName[] { Gesture.GestureName.peace });
        gestureList.Add(peace);

        Gesture metal = new Gesture(Gesture.GestureName.metal,
            new bool[] { true, true, false, false, true },
            new Vector3(0,0,0), new Vector3(1,0,0), new Vector3(0,1,0),
            new Gesture.GestureName[] { Gesture.GestureName.metal });
        gestureList.Add(metal);

        Gesture paper = new Gesture(Gesture.GestureName.paper,
            new bool[] { true, true, true, true, true },
            new Vector3(1,0,0), new Vector3(0,0,1), new Vector3(1,0,0),
            new Gesture.GestureName[] { Gesture.GestureName.punch_front, Gesture.GestureName.paper, Gesture.GestureName.scissor });
        gestureList.Add(paper);

        Gesture scissor = new Gesture(Gesture.GestureName.scissor,
            new bool[] { false, true, true, false, false },
            new Vector3(1,0,0), new Vector3(0,0,1), new Vector3(1,0,0),
            new Gesture.GestureName[] { Gesture.GestureName.punch_front, Gesture.GestureName.paper, Gesture.GestureName.scissor });
        gestureList.Add(scissor);

        Gesture devil = new Gesture(Gesture.GestureName.devil,
            new bool[] { false, true, false, false, true },
            new Vector3(0,0,0), new Vector3(1,0,0), new Vector3(0,1,0),
            new Gesture.GestureName[] { Gesture.GestureName.devil });
        gestureList.Add(devil);

        Gesture palmUp = new Gesture(Gesture.GestureName.palm_up,
            new bool[] { true, true, true, true, true },
            new Vector3(0,1,0), new Vector3(1,1,0), new Vector3(1,-1,0),
            new Gesture.GestureName[] { Gesture.GestureName.palm_down });
        gestureList.Add(palmUp);

        Gesture palmDown = new Gesture(Gesture.GestureName.palm_down,
            new bool[] { true, true, true, true, true },
            new Vector3(0,-1,0), new Vector3(1,-1,0), new Vector3(1,1,0),
            new Gesture.GestureName[] { Gesture.GestureName.palm_up });
        gestureList.Add(palmDown);

        Gesture palmSide = new Gesture(Gesture.GestureName.palm_side,
            new bool[] { true, true, true, true, true },
            new Vector3(0,0,1), new Vector3(0,0,1), new Vector3(1,0,0),
            new Gesture.GestureName[] { Gesture.GestureName.palm_side });
        gestureList.Add(palmSide);

        gestures = gestureList.ToArray();
        #endregion
    }

    public static Gesture FindGestureByName(Gesture.GestureName gestureName)
    {
        return Array.Find(gestures, g => (g.gestureName == gestureName));
    }

    public static Gesture ReadAnswerGesture(Gesture currentGesture, bool[] fingers)
    {
        return currentGesture.GetAnswerGesture(fingers);
    }
}