#ifndef _PREDICATE_H
#define _PREDICATE_H

#include "tuple.h"

// Types of boolean expressions
#define AND_EXPR 1
#define OR_EXPR 2
#define NOT_EXPR 3
#define EQ_EXPR 4
#define NEQ_EXPR 5
#define LT_EXPR 6
#define LTE_EXPR 7
#define GT_EXPR 8
#define GTE_EXPR 9

typedef struct bool_expr {
  // type of boolean expression
  int bool_type;
  // body of the expression
  union expr_type {

    // AND, OR not NOT expression
    struct log_expr{
      bool_expr *left;
      bool_expr *right;
    }l_expr;

    // relational expression: == , <>, >=, <=, <, >
    struct rel_expr{
      int arg1;
      int arg2;
    }r_expr;

  }expr_body;
}bool_expr;

// boolean expression construction functions
bool_expr *make_eq_expr(int arg1, int arg2);
bool_expr *make_neq_expr(int arg1, int arg2);
bool_expr *make_lt_expr(int arg1, int arg2);
bool_expr *make_lte_expr(int arg1, int arg2);
bool_expr *make_gt_expr(int arg1, int arg2);
bool_expr *make_gte_expr(int arg1, int arg2);
bool_expr *make_and_expr(bool_expr *left, bool_expr *right);
bool_expr *make_or_expr(bool_expr *left, bool_expr *right);
bool_expr *make_not_expr(bool_expr *left);

// boolean evaluation functions
bool eval_eq_expr(bool_expr *eq_expr, tuple *arg_tuple, tuple *cons);
bool eval_neq_expr(bool_expr *neq_expr, tuple *arg_tuple, tuple *cons);
bool eval_lt_expr(bool_expr *lt_expr, tuple *arg_tuple, tuple *cons);
bool eval_lte_expr(bool_expr *lte_expr, tuple *arg_tuple, tuple *cons);
bool eval_gt_expr(bool_expr *gt_expr, tuple *arg_tuple, tuple *cons);
bool eval_gte_expr(bool_expr *gte_expr, tuple *arg_tuple, tuple *cons);
bool eval_and_expr(bool_expr *expr, tuple *src, tuple *cons);
bool eval_or_expr(bool_expr *expr, tuple *src, tuple *cons);
bool eval_not_expr(bool_expr *expr, tuple *src, tuple *cons);
#endif 

