#ifndef _SCHEMA_H
#define _SCHEMA_H

#include <cstring>

// Numeric codes for the attribute data types
#define CHAR_TYPE   1
#define INT_TYPE    2
#define DOUBLE_TYPE 3

// Maximun size in bytes of an attribute or relation name
#define MAX_NAME 128


// Define the types supported by the DBMS

// Integer type
typedef int int_type;

// Double type (Floating-point)
typedef double double_type;

// Character type for character strings
typedef struct char_type{
  int len; // length of character string
  char *str; // the actual string (terminated by '\0')
}char_type;

// Attribute information structure
typedef struct attr_info{
  char attr_name[MAX_NAME]; // variable-sized attribute name string
  int  attr_type; // numeric code for the attribute data type 
  int  type_size; // size in bytes of the attribute data type
}attr_info;


// Relation information structure
typedef struct relation_info {
  char rel_name[MAX_NAME]; // name of the relation
  int  rel_card; // cardinality of the relation
  char rel_file[MAX_NAME]; // name of the file in which the relation is stored
  int  num_attrs; // number of attributes in the relation
  attr_info *attributes; // array for the information about attributes
}relation_info;

// Projection attribute
typedef struct proj_attr {
  // information about this projection attribute
  attr_info a_info;
  // position of the target attribute in the tuple
  int attr_pos;
}proj_attr;

// List of projections
typedef struct proj_attr_list{
  // number of projections
  int num_projs;
  // array with the actual projections
  proj_attr *projections;
}proj_attr_list;

/*
 * This is a utility function used to print the contents of a
 * relation schema information structure. This function is 
 * can be used for debugging purposes. The function assumes 
 * the relation information structure to be correct.
 * Input: pointer to the relation schema 
 * Output: none
 */
void print_relation_schema(relation_info *rel_info);

/*
 * This function is used to read the schema information for 
 * a relation R, and return a pointer to a relation information
 * structure. The function must always close the input data file
 * before exiting.
 * Input: the relation name relation_name
 * Input: a variable used to determine the status of the operation.
 * Ouput: A pointer to a relation information structure if the 
 * schema information is found. In this case, the status code should be
 * set to OK. Otherwise, the function should return the NULL pointer,
 * and the status code should indicate the cause for the error,
 * which could be one of : FILE_NOT_FOUND, ILLEGAL_FILE_FORMAT, NO_MEMORY.
 */

relation_info *get_relation_info(const char *relation_name,
				 int& status);


#endif
