 (defn >zero? [x] (> x 0))
 (defn >=zero? [x] (>= x 0))
 
-(def Letter s/Str)
+(def Letter schema/Str)
+(s/def ::letter string?)
 
-(def ByteRange (s/constrained s/Num in-byte-range?))
+(def ByteRange (schema/constrained schema/Num in-byte-range?))
+(s/def ::byterange (s/and integer? >=zero? in-byte-range?))
 
-(def Color [(s/one ByteRange "r")
-            (s/one ByteRange "g")
-            (s/one ByteRange "b")
-            (s/one ByteRange "a")])
+(def Color [(schema/one ByteRange "r")
+            (schema/one ByteRange "g")
+            (schema/one ByteRange "b")
+            (schema/one ByteRange "a")])
+;; RGBA
+(s/def ::color (s/tuple ::byterange ::byterange ::byterange ::byterange))
 
 ;;
 ;; Type of Terminal Blocks
 ;;
 
-(def TextBlock {:type (s/eq "Text")
+(def TextBlock {:type (schema/eq "Text")
                 :foreground-color Color
                 :background-color Color
-                :style {(s/optional-key :bold) s/Bool
-                        (s/optional-key :underline) s/Bool
-                        (s/optional-key :italic) s/Bool}
+                :style {(schema/optional-key :bold) schema/Bool
+                        (schema/optional-key :underline) schema/Bool
+                        (schema/optional-key :italic) schema/Bool}
                 :text Letter})
 
-(def EmptyBlock {:type (s/eq "Empty")
+(s/def ::foreground-color ::color)
+(s/def ::background-color ::color)
+(s/def ::style (s/keys :opt-un [::bold ::underline ::italic]))
+
+(s/def ::textblock 
+  (s/keys 
+   :req-un [::type
+            ::foreground-color
+            ::background-color
+            ::style]))
+
+(def EmptyBlock {:type (schema/eq "Empty")
                  :foreground-color Color
                  :background-color Color})
 
 ;; Checking type of Terminal Block
 (defn is-type? [xs x] (= (:type xs) x))
 (def TerminalBlock
-  (s/conditional
+  (schema/conditional
      #(is-type? % "Text")
      TextBlock
      :else


(def TerminalFont
  "Schema for a terminal font"
  {:family s/Str
   :ratio [(s/one s/Num "x-ratio")
           (s/one s/Num "y-ratio")]})

(def TerminalOffset
  [(s/one s/Num "col-offset")
   (s/one s/Num "row-offset")])

(def TerminalOptions
  "Schema for Terminal Options"

(ns fluch.schemas
  (:require [schema.core :as schema :include-macros true]
            [cljs.spec :as s]))

(enable-console-print!)

(defn in-unit-interval? [x]
  (and (>= x 0.0) (<= 1.0)))
(def UnitInterval (schema/constrained schema/Num in-unit-interval?))
(s/def ::unit-interval (s/and integer? in-unit-interval?))

(defn in-byte-range? [x]
  (and (<= x 255) (>= x 0) (integer? x)))
