{-# LINE 1 "src/Database/EJDB2/IndexMode.hsc" #-}
{-# LANGUAGE CPP #-}

module Database.EJDB2.IndexMode where


import           Foreign
import           Foreign.C.String
import           Foreign.C.Types



-- | Index creation mode.
newtype IndexMode = IndexMode { unIndexMode :: CUChar }

-- | Marks index is unique, no duplicated values allowed.
uniqueIndexMode    = IndexMode 1
{-# LINE 17 "src/Database/EJDB2/IndexMode.hsc" #-}
-- | Index values have string type.
--
-- Type conversion will be performed on atempt to save value with other type.
strIndexMode    = IndexMode 4
{-# LINE 21 "src/Database/EJDB2/IndexMode.hsc" #-}
-- | Index values have signed integer 64 bit wide type.
--
-- Type conversion will be performed on atempt to save value with other type.
i64IndexMode    = IndexMode 8
{-# LINE 25 "src/Database/EJDB2/IndexMode.hsc" #-}
-- | Index value have floating point type.
--  /Internally floating point numbers are converted to string with precision of 6 digits after decimal point./
f64IndexMode    = IndexMode 16
{-# LINE 28 "src/Database/EJDB2/IndexMode.hsc" #-}

allIndexMode :: [IndexMode]
allIndexMode = [uniqueIndexMode, strIndexMode, i64IndexMode , f64IndexMode]

combineIndexMode :: [IndexMode] -> IndexMode
combineIndexMode = IndexMode . foldr ((.|.) . unIndexMode) 0

unCombineIndexMode :: IndexMode -> [IndexMode]
unCombineIndexMode (IndexMode (CUChar oflags)) = filter f allIndexMode
          where
            f = \(IndexMode (CUChar value)) -> value .&. oflags /= 0