#include <sys/types.h>
#include <functional>
#include <string.h>
#include <stdio.h>
using namespace std;

#include "error.h"
#include "utility.h"
#include "catalog.h"

// define if debug output wanted


//
// Retrieves and prints information from the catalogs about the for the
// user. If no relation is given (relation is NULL), then it lists all
// the relations in the database, along with the width in bytes of the
// relation, the number of attributes in the relation, and the number of
// attributes that are indexed.  If a relation is given, then it lists
// all of the attributes of the relation, as well as its type, length,
// and offset, whether it's indexed or not, and its index number.
//
// Returns:
// 	OK on success
// 	error code otherwise
//

const Status RelCatalog::help(const string & relation)
{
  Status status;
  RelDesc rd;
  AttrDesc *attrs;
  int attrCnt;

  if (relation.empty()) return UT_Print(RELCATNAME);
  else {
//	UT_Print(relation);
        /*cout << "Relation name: " << ATTRCATNAME << endl << endl;

	int i;
 	status = relCat->getInfo(ATTRCATNAME, rd);
 	if(status != OK) return status;

	status = attrCat->getRelInfo(ATTRCATNAME, attrCnt, attrs);
	if(status != OK) return status;
	
	int *attrWidth;
	status = UT_computeWidth(attrCnt, attrs, attrWidth);
	if(status != OK) return status;
	for(i = 0; i < attrCnt; i++) {
	    printf("%-*.*s ", attrWidth[i], attrWidth[i],
		   attrs[i].attrName);
  	}
        printf("\n");

	for(i = 0; i < attrCnt; i++) {
	for(int j = 0; j < attrWidth[i]; j++)
	      putchar('-');
	      printf("  ");
        }
        printf("\n");
        
	status = attrCat->getRelInfo(relation, attrCnt, attrs);
	if(status != OK) return status;

	for (i = 0; i< attrCnt; i++){
	      int k = 0;
	      printf("%-*.*s ", attrWidth[k], attrWidth[k], attrs[i].relName);
	      printf("%-*.*s ", attrWidth[k+1], attrWidth[k+1], attrs[i].attrName);
	      printf("%-*d ",   attrWidth[k+2], attrs[i].attrType);
	      printf("%-*d ",   attrWidth[k+3], attrs[i].attrOffset);
	      printf("%-*d ",   attrWidth[k+4], attrs[i].attrLen);
	      printf("\n");
	}
        delete attrs;*/
	return OK;
  }


  return OK;
}
