 ;;; # ------------------------------------------------------------ "RESOLVED" TYPES: FIELD + VALUE ------------------------------------------------------------
 
 ;; Field is the expansion of a Field ID in the standard QL
-(s/defrecord Field [field-id           :- s/Int
+(s/defrecord Field [field-id           :- IntGreaterThanZero
                     field-name         :- s/Str
                     field-display-name :- s/Str
                     base-type          :- (apply s/enum field/base-types)
                     special-type       :- (s/maybe (apply s/enum field/special-types))
-                    table-id           :- s/Int
+                    table-id           :- IntGreaterThanZero
                     schema-name        :- (s/maybe s/Str)
                     table-name         :- s/Str
-                    position           :- (s/maybe s/Int)
+                    position           :- (s/maybe s/Int) ; TODO - int >= 0
                     description        :- (s/maybe s/Str)
-                    parent-id          :- (s/maybe s/Int)
+                    parent-id          :- (s/maybe IntGreaterThanZero)
                     ;; Field once its resolved; FieldPlaceholder before that
                     parent             :- s/Any]
   IField

                      "Valid order-by subclause"))


(def Page (s/named {:page  s/Int
                    :items s/Int}
                   "Valid page clause"))




;; These are just used by the QueryExpander to record information about how joins should occur.

(def IntGreaterThanZero (s/constrained s/Int
                                       (partial < 0)
                                       "Integer greater than zero"))

(s/defrecord JoinTableField [field-id   :- IntGreaterThanZero
                             field-name :- s/Str])

(s/defrecord JoinTable [source-field :- JoinTableField
                        pk-field     :- JoinTableField
                        table-id     :- IntGreaterThanZero
                        table-name   :- s/Str])

;;; # ------------------------------------------------------------ PROTOCOLS ------------------------------------------------------------
