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

namespace Machete {
	public class Cheater : Student {

    [SerializeField]
    GameObject senderSign;
    [SerializeField]
    GameObject receiverSign;

    private Message question;
    [SerializeField]
    private int ticksToReply = 1;
    [SerializeField]
    private int ticksCount;

    public Grid Grid {
      set { grid = value; }
    }
    protected Grid grid;

    public bool IsPlayable;

    protected override void Start() {
      base.Start();
    }

    public override bool TakeMessage(Message message) {
      if (message.Receiver != this) {
        return true;
      }
      message.gameObject.SetActive(false); // TODO: Mark as response ready.
      question = message;
      ticker.OnTick += ResolveQuestion;
      return true;
    }

    void ResolveQuestion() {
      ticksCount++;
      if (ticksCount < ticksToReply - 1) {
        return;
      }
      // Done.
      ticker.OnTick -= ResolveQuestion;
      // Respond message
      question.Receiver = question.Sender;
      question.Sender = this;
      question.Resolved = true;
      question.Planning = true;
      // TODO: Mark as response ready.
      question.gameObject.SetActive(true);
      this.MarkAsSender(true);
    }

    public void MarkAsSender(bool active) {
      senderSign.SetActive(active);
    }

    public void MarkAsReceiver(bool active) {
      receiverSign.SetActive(active);
    }
	}
}
