using UnityEngine;
using UnityEngine.Playables;

public class LittleKid : MonoBehaviour, IInteractable
{

    [SerializeField] private PlayableDirector director;
    [SerializeField] private PlayableDirector digDirector;
    [SerializeField] private PlayableDirector fadeOut;
    private string[] lines;
    public Dialogue dialogue;
    private bool hasInteracted = false;
    [SerializeField] private GameObject bubbleBlower;
    
    public void Interact()
    {
        if(!hasInteracted)
        {
            lines = new string[]{
                "Hey, want to go play in the sandbox?",
                "We can dig for treasure!"
            };
            dialogue.StartDialogue(lines, "Child (Old Man)", this.gameObject, "ChildResponse");
        }
        else
        {
            lines = new string[]{
                "I think I found something!",
                "Quick, help me dig this up!"
            };
            dialogue.StartDialogue(lines, "Little Boy", this.gameObject, "DigStuff");
        }
    }

    public void ChildResponse()
    {
        lines = new string[]{
            "Sure!"
        };
        dialogue.StartDialogue(lines, "Little Boy", this.gameObject, "GoToSandbox");
    }

    public void GoToSandbox()
    {
        director.Play();
        hasInteracted = true;
    }

    public void DigStuff()
    {
        digDirector.Play();
    }

    public void DoneDigging()
    {
        bubbleBlower.SetActive(true);
        lines = new string[]{
            "W-woah! It's a magic wand!"
        };
        dialogue.StartDialogue(lines, "Child (Old Man)", this.gameObject, "MagicWand");
    }

    public void MagicWand()
    {
        lines = new string[]{
            "This is perfect! Now all I need is…",
            "...A friend.",
            "...And a sand castle!!!"
        };
        dialogue.StartDialogue(lines, "Little Boy", this.gameObject, "SceneEnd");
    }

    public void SceneEnd()
    {
        fadeOut.Play();
    }
}
