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

namespace ToadieTechnika.GGJ2018Game
{
    public class BluetoothObject : MonoBehaviour
    {
        Vector2 m_NormalDoorPos;
        [SerializeField]
        Transform m_LockTransform;

        [SerializeField]
        Transform m_DoorTransform;

        [SerializeField]
        Vector2 m_OpenedDoorPos;
        Collider2D[] m_GetTransmissionColliders;

        bool m_isOpened;
        bool m_isInit;

        #region Properties
        public Collider2D[] GetTransmissionColliders
        {
            get { return m_GetTransmissionColliders; }
            set { m_GetTransmissionColliders = value; }
        }

        public bool IsOpened
        {
            get { return m_isOpened; }
            set { m_isOpened = value; }
        }
        #endregion

        void Start()
        {
            m_NormalDoorPos = m_DoorTransform.localPosition;
            NormalizeDoor();
            m_isInit = true;
        }

        void OnEnable()
        {
            if (m_isInit)
                NormalizeDoor();
        }

        void Update()
        {
            m_DoorTransform.localPosition = Vector2.Lerp(m_DoorTransform.localPosition, m_isOpened ? m_OpenedDoorPos : m_NormalDoorPos, Time.deltaTime * 6f);
        }

        public void NormalizeDoor()
        {
            m_DoorTransform.localPosition = m_NormalDoorPos;
            m_isOpened = false;
        }

        #if UNITY_EDITOR
        void OnDrawGizmos()
        {
            Gizmos.color = Color.red;
            Gizmos.DrawLine(m_DoorTransform.position, m_LockTransform.position);
        }
        #endif
    }
}