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

public class Gesture
{
    public enum GestureName
    {
        punch_front,
        punch_up,
        punch_down,
        hifive,
        peace,
        metal,
        paper,
        scissor,
        devil,
        palm_up,
        palm_down,
        palm_side
    }

    public GestureName gestureName;
    public bool[] fingersOut;
    public Vector3 direction, palmNormal, indexDirection;

    public GestureName[] answers;

    public Gesture(GestureName gName, bool[] fingers, Vector3 dir, Vector3 normal, Vector3 indexDir, GestureName[] responses)
    {
        gestureName = gName;
        fingersOut = fingers;
        direction = dir;
        palmNormal = normal;
        indexDirection = indexDir;
        answers = responses;
    }

    public Gesture GetAnswerGesture(bool[] fingers)
    {
        for (int i = 0; i < answers.Length; i++)
        {
            Gesture gesture = GestureManager.FindGestureByName(answers[i]);
            if (IsAnswerGesture(gesture, fingers))
                return gesture;
        }
        return null;
    }

    public bool IsAnswerGesture(Gesture gesture, bool[] fingers)
    {
        for (int i = 0; i < fingers.Length; i++)
        {
            if (fingers[i] != gesture.fingersOut[i])
                return false;
        }
        return true;
    }

    public Vector3 GetPlayerIndexDirection()
    {
        Vector3 indexDir;
        switch (gestureName)
        {
			case GestureName.palm_down:
				indexDir = new Vector3(-indexDirection.x, indexDirection.y, indexDirection.z);
				break;
            case GestureName.palm_up:
                indexDir = new Vector3(indexDirection.x, -indexDirection.y, indexDirection.z);
                break;
			case GestureName.punch_up:
				indexDir = new Vector3(-1, 1, 0);
				break;
			case GestureName.palm_side:
				indexDir = -indexDirection;
				break;
			case GestureName.paper:
				indexDir = -indexDirection;
				break;
			case GestureName.punch_down:
				indexDir = new Vector3(-1, -1, 0);
				break;
            default:
                indexDir = indexDirection;
                break;
        }
        return indexDir;
    }

    public Vector3 GetPlayerPalmDirection()
    {
        Vector3 palmDir;
        switch (gestureName)
        {
            case GestureName.palm_down:
				palmDir = new Vector3(-palmNormal.x, palmNormal.y, palmNormal.z);
				break;
            case GestureName.palm_up:
				palmDir = new Vector3(-palmNormal.x, -palmNormal.y, palmNormal.z);
                break;
			case GestureName.punch_down:
				palmDir = -palmNormal;
				break;
            default:
                palmDir = -palmNormal;
                break;
        }
        return palmDir;
    }
}
