/**
 * Copyright (c) 2021 Dominic Masters
 * 
 * This software is released under the MIT License.
 * https://opensource.org/licenses/MIT
 */

#pragma once
#include "../../libs.h"
#include  "../ui/vntextbox.h"
#include "../../util/array.h"
#include "../../display/animation/timeline.h"
#include "../../display/animation/queue.h"
#include "../vncharacter.h"
#include "../../engine/engine.h"

typedef struct _vnconversation_t vnconversation_t;

typedef struct {
  /** Pointer to the original conversation */
  vnconversation_t *conversation;

  /** Storage for pointer to text for text conversation elements */
  char *text;

  /** Character this conversation piece belongs to */
  vncharacter_t *character;

  /** Character's emotion */
  uint8_t emotion;
} vnconversationitemdata_t;

/** Representation of a conversation, laid out similarly to a timeline. */
typedef struct _vnconversation_t {
  /** Internal Textbox for text elements */
  vntextbox_t textbox;

  /** Data Storage for items' data */
  vnconversationitemdata_t itemData[ANIMATION_QUEUE_ITEM_MAX];

  /** Internal Queue for queueing the conversation */
  queue_t actionQueue;
} vnconversation_t;

/**
 * Initialize the conversation set. After adding your first conversation element
 * then ensure you call vnConversationNext to begin the conversation.
 * @param convo Conversation to initialize.
 * @param font Font to initialize with.
 * @param tex GUI Texture.
 */
void vnConversationInit(vnconversation_t *convo, font_t *font, texture_t *text);

/**
 * Add a text element to the conversation.
 * @param convo Conversation to add to.
 * @return The pointer to the queue element.
 */
queueaction_t * vnConversationAdd(vnconversation_t *convo);

/**
 * Updates the conversation logic and the wrapped textbox.
 * @param convo Conversation to update.
 * @param engine Engine used to update.
 */
void vnConversationUpdate(vnconversation_t *convo, engine_t *engine);

/**
 * Renders the conversation, mostly just a wrapper for the textbox.
 * @param convo Conversation to render.
 * @param engine Engine to use for rendering.
 * @param shader Shader to use while rendering.
 */
void vnConversationRender(
  vnconversation_t *convo, engine_t *engine, shader_t *shader
);

/**
 * Dispose the conversation when finished.
 * @param convo Conversation to dispose.
 */
void vnConversationDispose(vnconversation_t *convo);