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

public class DispenseIceStation : Station
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public override void InteractInitiated()
    {

    }

    public bool OperatingMachine = false;

    public override void PlayerInteract()
    {
        IcePlatformStation icePlatform = GetComponent<IcePlatformStation>();

        if (icePlatform.drinkHolder.CurrentlyHoldingADrink && !OperatingMachine)
        {
            OperatingMachine = true;
            StartCoroutine(OperateMachine());
        }
    }

    private IEnumerator OperateMachine()
    {
        IcePlatformStation icePlatform = GetComponent<IcePlatformStation>();
        PlayerInfo player = GetComponent<PlayerInfo>();

        Drink drink1 = icePlatform.drinkHolder.GetHeldDrink();

        // show progress bar

        // pause for time
        float operationTime = 3.0f;

        drink1.progressFillDuration = operationTime;
        drink1.progressFillTime = Time.time + operationTime;
        drink1.drinkOrigination = DrinkRenderMode.Progress;

        PlayAssociatedAudio();

        yield return new WaitForSeconds(operationTime);

        if (drink1.Sealed)
        {
            player.SayDialogue("Drink is sealed");
        }
        else if (drink1.IceLevel < 2)
            drink1.IceLevel++;

        drink1.drinkOrigination = DrinkRenderMode.Physical;

        OperatingMachine = false;
    }

}
