{-# 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 { IndexMode -> CUChar
unIndexMode :: CUChar }

-- | Marks index is unique, no duplicated values allowed.
uniqueIndexMode :: IndexMode
uniqueIndexMode    = CUChar -> IndexMode
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
strIndexMode    = CUChar -> IndexMode
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
i64IndexMode    = CUChar -> IndexMode
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
f64IndexMode    = CUChar -> IndexMode
IndexMode 16
{-# LINE 28 "src/Database/EJDB2/IndexMode.hsc" #-}

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

combineIndexMode :: [IndexMode] -> IndexMode
combineIndexMode :: [IndexMode] -> IndexMode
combineIndexMode = CUChar -> IndexMode
IndexMode (CUChar -> IndexMode)
-> ([IndexMode] -> CUChar) -> [IndexMode] -> IndexMode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (IndexMode -> CUChar -> CUChar) -> CUChar -> [IndexMode] -> CUChar
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (CUChar -> CUChar -> CUChar
forall a. Bits a => a -> a -> a
(.|.) (CUChar -> CUChar -> CUChar)
-> (IndexMode -> CUChar) -> IndexMode -> CUChar -> CUChar
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IndexMode -> CUChar
unIndexMode) 0

unCombineIndexMode :: IndexMode -> [IndexMode]
unCombineIndexMode :: IndexMode -> [IndexMode]
unCombineIndexMode (IndexMode (CUChar oflags :: Word8
oflags)) = (IndexMode -> Bool) -> [IndexMode] -> [IndexMode]
forall a. (a -> Bool) -> [a] -> [a]
filter IndexMode -> Bool
f [IndexMode]
allIndexMode
          where
            f :: IndexMode -> Bool
f = \(IndexMode (CUChar value :: Word8
value)) -> Word8
value Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
oflags Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= 0