using UnityEngine;
using WS;
using static InputActions;
using static UnityEngine.InputSystem.InputAction;

[ObjectSystem]
public class InputManagerAwakeSystem : AwakeSystem<InputManager>
{
    public override void Awake(InputManager self)
    {
        self.Awake();
    }
}

[ObjectSystem]
public class InputManagerUpdateSyste : UpdateSystem<InputManager>
{
    public override void Update(InputManager self)
    {
        self.Update();
    }
}

///<summary>ÊäÈë¹ÜÀíÆ÷</summary>
public class InputManager : SingleComponent<InputManager>
{
    /// <summary>VRµã»÷</summary>
    public bool triggerPressed;
    public Vector2 moveInput;
    public Vector3 cameraPos;
    public Quaternion cameraRot;
    public Vector3 pointPos;
    public Quaternion pointRot;

    public PlayerActions player;
    public CameraActions camera;
    public UIActions ui;

    public void Awake()
    {
        RegisterInputEvent();
    }

    public void Update() { }

    private void RegisterInputEvent()
    {
        var input = new InputActions();
        player = input.Player;
        camera = input.Camera;
        ui = input.UI;
        player.Enable();
        camera.Enable();
        ui.Enable();
        player.Move.started += PlayerMoveStarted;
        player.Move.performed += PlayerMovePerformed;
        player.Move.canceled += PlayerMoveCanceled;
        camera.Pos.started += CameraPosStarted;
        camera.Pos.performed += CameraPosPerformed;
        camera.Pos.canceled += CameraPosCanceled;
        camera.Rot.started += CameraRotStarted;
        camera.Rot.performed += CameraRotPerformed;
        camera.Rot.canceled += CameraRotCanceled;

        ui.Click.started += UIClickStarted;
        ui.Click.performed += UIClickPerformed;
        ui.Click.canceled += UIClickCanceled;
    }

    private void PlayerMoveStarted(CallbackContext obj)
    {
        moveInput = obj.ReadValue<Vector2>();
    }

    private void PlayerMovePerformed(CallbackContext obj)
    {
        moveInput = obj.ReadValue<Vector2>();
    }

    private void PlayerMoveCanceled(CallbackContext obj)
    {
        moveInput = obj.ReadValue<Vector2>();
    }

    private void CameraPosStarted(CallbackContext obj)
    {
        cameraPos = obj.ReadValue<Vector3>();
    }

    private void CameraPosPerformed(CallbackContext obj)
    {
        cameraPos = obj.ReadValue<Vector3>();
    }

    private void CameraPosCanceled(CallbackContext obj)
    {
        cameraPos = obj.ReadValue<Vector3>();
    }

    private void CameraRotStarted(CallbackContext obj)
    {
        cameraRot = obj.ReadValue<Quaternion>();
    }

    private void CameraRotPerformed(CallbackContext obj)
    {
        cameraRot = obj.ReadValue<Quaternion>();
    }

    private void CameraRotCanceled(CallbackContext obj)
    {
        cameraRot = obj.ReadValue<Quaternion>();
    }

    private void UIClickStarted(CallbackContext obj)
    {
        triggerPressed = obj.ReadValue<bool>();
    }

    private void UIClickPerformed(CallbackContext obj)
    {
        triggerPressed = obj.ReadValue<bool>();
    }

    private void UIClickCanceled(CallbackContext obj)
    {
        triggerPressed = obj.ReadValue<bool>();
    }
}
