// Fill out your copyright notice in the Description page of Project Settings.


#include "CoffeeMachineActor.h"

#include "Components/InteractionWidgetComponent.h"
#include "Faye/Components/CoffeeMachineController.h"


ACoffeeMachineActor::ACoffeeMachineActor()
{
	PrimaryActorTick.bCanEverTick = true;
	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
	SetRootComponent(RootComponent);
	
	WidgetComponent = CreateDefaultSubobject<UInteractionWidgetComponent>(TEXT("WidgetComponent"));
	WidgetComponent->SetupAttachment(RootComponent);
	
	CoffeeMachineController = CreateDefaultSubobject<UCoffeeMachineController>(TEXT("CoffeeMachineController"));
}

void ACoffeeMachineActor::ToggleInteractableUI_Implementation(bool bActive)
{
	if (bActive && !IInteractableActorInterface::Execute_IsInteractable(this))
	{
		return;
	}
	
	IInteractableActorInterface::ToggleInteractableUI_Implementation(bActive);
	
	if (WidgetComponent)
	{
		WidgetComponent->ToggleWidget(bActive);
	}
}

void ACoffeeMachineActor::Interact_Implementation(AActor* InteractionInstigator)
{
	IInteractableActorInterface::Interact_Implementation(InteractionInstigator);
	
	CoffeeMachineController->ToggleCoffeeMaking(true);
}

void ACoffeeMachineActor::BeginPlay()
{
	Super::BeginPlay();
}


