/*
 * main_queue.c
 */
#include "queue.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LINE_LENGTH 200

int main () {
  char input[MAX_LINE_LENGTH];
  char cmd[MAX_LINE_LENGTH];
  int value;
  Queue* the_queue = Queue_Allocate();
  if (the_queue == NULL) {
    return EXIT_FAILURE;
  }
  
  while (1) {
    printf ("Enter command (add, delete, list quit) : \n");

    // read from stdin (stdin is the terminal input)
    fgets (input, MAX_LINE_LENGTH, stdin);

    // Check for add command
    if (sscanf (input, "add %d", &value) == 1) {
      Queue_Add(the_queue, value);
      Queue_Print(the_queue);
    }

    // Get the command from the ipnut.
    // %s will not include leading and trailing whitespace
    if(sscanf(input, "%s", cmd) == 0) {
      // if no non-whitespace is found
      // set cmd to be ""
      cmd[0] = '\0';
    }

    // Check for delete command
    if (strcmp(cmd, "delete") == 0) {
      Queue_Remove(the_queue);
      Queue_Print(the_queue);
    }

    // Check for list command
    if (strcmp(cmd, "list") == 0) {
      Queue_Print(the_queue);
    }

    // check for quit command
    if (strcmp(cmd, "quit") == 0) {
      Queue_Clear(the_queue);
      break;
    }
  }

  Queue_Free(the_queue);
  
  return 0;
}
