#*********************************************************
# name dict::fl_list
# returns list of fields for given entity
#*********************************************************
proc dict::fl_list {entity} {
    upvar #0 $entity data
    set entity_id [$entity identifier]
    set fld_lst [fld_list $entity_id]
    return [list_table $fld_lst [lindex [fieldClass::prefix] 0] field dict]
}

# ******************************************************
# name dict::fklist
# make list of fields and checks for each field
# if it is a foreign key
# **************************************************
proc dict::fklist {entity args} {
 upvar #0 $entity data
 set foreign_lst ""
 set fld_lst [$data(class)::list_of_fields $entity $args]
      # construct primaries list
    foreach field $fld_lst {
      if { [$field fkey]==[truevalue]} {
                      lappend foreign_lst $field
         }
      }
 return $foreign_lst
}
# ******************************************************
# name dict::prlist
# makes list of fields and checks for each field
# if it is a primary key
# *******************************************************
proc dict::prlist {entity args} {
 upvar #0 $entity data
   set prim_lst ""

 set fld_lst [$data(class)::list_of_fields $entity $args]
      # construct primaries list
    foreach field $fld_lst {
      if { [$field pkey]==[truevalue]} {
                      lappend prim_lst $field
         }
      }
 return $prim_lst
}

# ************************************************************
# name dict::index_list
# returns list of indexes for given entity
# ************************************************************
proc dict::index_list {entity} {
      set entity_id [$entity IDENTIFIER]
      set indx_lst [idx_list $entity_id]
      return [list_table $indx_lst [lindex [indexClass::prefix] 0] index dict]
}
# ********************************************************
# name dict::relations_out
# returns list of out relations for given entity
# *********************************************************
proc dict::relations_out {entity} {
   # regsub {ent} $entity "" entity_id
   set rel_out [out_rel_list [$entity IDENTIFIER]]
   return [list_table $rel_out [lindex [relationClass::prefix] 0] relation dict]
}
# *****************************************************
# name dict::relations_in
# returns list of in relations for given entity
# ******************************************************
proc dict::relations_in {entity} {
   set rel_in [in_rel_list [$entity IDENTIFIER]]
   return [list_table $rel_in [lindex [relationClass::prefix] 0] relation dict]
}
proc dict::get_entity_id {entity} {
 return [$entity I_ENTITY]
}

proc entityClass::prefix {} {
 return {ent identifier identifier}
}

#******************************************
# name dict::get_ent_name
# returns name of given entity
#***************************************
proc dict::get_ent_name {entity} {
 set name_r [$entity attr NAME]
 return $name_r
}

#************************************
# name dict::get_ent_path
# returns the path of given entity
#************************************
proc dict::get_ent_path {entity} {
 set xpath  [$entity attr LOCATION] 
 if {$xpath == "" } {
	set xmodel [dict get_model] 
    set xpath  [$xmodel attr LOCATION] 
 }
 set len [string length $xpath]
 if { $len > 0 } {
	set last [string range $xpath [expr $len - 1] $len]
	if { $last != "\\" } {
	   set xpath "$xpath\\"
	}
 }
 return $xpath
}

#************************************
# name dict::get_ent_driver
# returns the driver of given entity
#************************************
proc dict::get_ent_driver {entity} {
 set xdriver  [$entity attr INDEX_TYPE] 
 switch -exact xdriver {
	"NDX" {return "DBFNDX"}
	"NTX" {return "DBFNTX"}
	"CDX" {return "DBFCDX"}
	"IDX" {return "DBFCDX"}
	"MDX" {return "DBFMDX"}
 }
 return $xdriver
}
#************************************
# name dict::ent_pk_index
# returns the primary index of given entity
#************************************
proc dict::ent_pk_index {entity} {
   set index [get_idx [$entity I_INDEX]]
   return [list_table $index [lindex [indexClass::prefix] 0] index dict]
}

#************************************
# name entity_dict::update
# update attr_name with value 
#************************************
proc entity_dict::update {entity attr_name value} {
   _upd_ent [$entity IDENTIFIER] $attr_name $value
}  
# **************************************************
# name dict::ent_is_xbase
# checks if the field is a foreign key
# returns current values of truevalue or falsevalue
# ***************************************************

proc dict::ent_is_xbase {entx} {
     set ent_id [$entx IDENTIFIER]
     set res [_ent_is_xbase $ent_id]

      # not a foreign key?
      if {$res == 0} {
         set res [falsevalue]
      } else {
         set res [truevalue]
      }
    return $res
}





