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

public class WireSocket : MonoBehaviour
{
    public Character Character;
    public TransmissionData SenderTransmissionData;
    public WireHead ConnectedWireHead;

    public bool IsReciver;
    public bool IsSender;

    public GameObject SendLight;
    public GameObject ReceiverLight;

    void Awake()
    {
        Character = GetComponent<Character>();
    }


    public void ResetWireSocket()
    {
        LightOff();
        SenderTransmissionData = null;
        IsReciver = false;
        IsSender = false;
        ConnectedWireHead = null;
    }

    public void InitWireSocket(List<TransmissionData> datas)
    {
        if (datas.Any(d => d.ToCharacterId == Character.CharId))
        {
            IsReciver = true;
            ShowReceiverLight();
        }
        if (datas.Any(d => d.FromCharacterId == Character.CharId))
        {
            IsSender = true;
            ShowSenderLight();
        }
        if (datas.Count > 0 && datas.FirstOrDefault(d => d.FromCharacterId == Character.CharId) != null)
        {
            SenderTransmissionData = datas.First(d => d.FromCharacterId == Character.CharId);
        }
    }

    public void ShowReceiverLight()
    {
        SendLight.SetActive(false);
        ReceiverLight.SetActive(true);
    }

    public void ShowSenderLight()
    {
        SendLight.SetActive(true);
        ReceiverLight.SetActive(false);
    }

    public void LightOff()
    {
        SendLight.SetActive(false);
        ReceiverLight.SetActive(false);
    }
}
