/*
 * system_list.h
 *
 * Definition and declarations of responses queue
 * 
 */
 
 
#ifndef _SYSTEM_LIST_H_
#define _SYSTEM_LIST_H_

#include <config.h>

/* response_t */
typedef struct {
	char title[MAX_BOOKNAME_SIZE];
	char counter[MAX_COUNTER_SIZE];
	int weight;
	char neighbours[MAX_NEIGHBOURS_SIZE];
	char reason[MAX_REASON_SIZE];
} system_res_search_t;

typedef struct {
	char title[MAX_BOOKNAME_SIZE];
	char counter[MAX_COUNTER_SIZE];
	char reason[MAX_REASON_SIZE];
	int size;
	char* cover;
} system_res_take_t;

typedef struct {
	char title[MAX_BOOKNAME_SIZE];
	char counter[MAX_COUNTER_SIZE];
	char reason[MAX_REASON_SIZE];
} system_res_release_t;


typedef enum {
	SEARCH = 1,
	TAKE = 2,
 	RELEASE = 3,
  	RETURN = 4,
} system_res_type_t;

typedef enum {
	OK = 1,
	ERROR = 2,
} system_res_status_t;


/* lst_iitem - each element of the list points to the next element */
typedef struct sys_lst_iitem {
	system_res_status_t status;
	system_res_type_t type;
   	union {
    	system_res_search_t search;
    	system_res_take_t take;
		system_res_release_t release;
   	} system_response;
	struct sys_lst_iitem *next;
} sys_lst_iitem_t;

/* list_t */
typedef struct {
	sys_lst_iitem_t *first;
	sys_lst_iitem_t *last;
} sys_list_t;


/* lst_new - allocates memory for list_t and initializes it */
sys_list_t* sys_lst_new();

/* lst_destroy - frees memory of list_t and all its items */
void sys_lst_destroy(sys_list_t *);

/* lst_insert - inserts a new item with value 'response' in list 'list' */
void sys_lst_insert(sys_list_t *list, sys_lst_iitem_t *item);

/* lst_print - prints the content of list 'list' to standard output */
void sys_lst_print(sys_list_t *list);

/* lst_pop - removes the first item from the list 'list' and returns a pointer to it */
sys_lst_iitem_t* sys_lst_pop(sys_list_t *list);

#endif
