{-# LINE 1 "src/Database/EJDB2/Result.hsc" #-}
{-# LANGUAGE CPP #-}
module Database.EJDB2.Result where

import           Foreign
import           Foreign.C.Types



type RC = CUIntMax

checkRC :: RC -> IO ()
checkRC :: RC -> IO ()
checkRC rc :: RC
rc = do
    let result :: Result
result = RC -> Result
decodeRC RC
rc
    if Result
result Result -> Result -> Bool
forall a. Eq a => a -> a -> Bool
== Result
Ok then () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return () else String -> IO ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ Result -> String
forall a. Show a => a -> String
show Result
result

checkRCFinally :: IO a -> RC -> IO a
checkRCFinally :: IO a -> RC -> IO a
checkRCFinally computation :: IO a
computation rc :: RC
rc = do
    let result :: Result
result = RC -> Result
decodeRC RC
rc
    if Result
result Result -> Result -> Bool
forall a. Eq a => a -> a -> Bool
== Result
Ok
        then IO a
computation
        else do
            IO a
computation
            String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> IO a) -> String -> IO a
forall a b. (a -> b) -> a -> b
$ Result -> String
forall a. Show a => a -> String
show Result
result

data Result =
      Ok                          -- ^ No error.
    | ErrorFail                   -- ^ Unspecified error.
    | ErrorErrno                  -- ^ Error with expected errno status set.
    | ErrorIoErrno                -- ^ IO error with expected errno status set.
    | ErrorNotExists              -- ^ Resource is not exists.
    | ErrorReadonly               -- ^ Resource is readonly.
    | ErrorAlreadyOpened          -- ^ Resource is already opened.
    | ErrorThreading              -- ^ Threading error.
    | ErrorThreadingErrno         -- ^ Threading error with errno status set.
    | ErrorAssertion              -- ^ Generic assertion error.
    | ErrorInvalidHandle          -- ^ Invalid HANDLE value.
    | ErrorOutOfBounds            -- ^ Invalid bounds specified.
    | ErrorNotImplemented         -- ^ Method is not implemented.
    | ErrorAlloc                  -- ^ Memory allocation failed.
    | ErrorInvalidState           -- ^ Illegal state error.
    | ErrorNotAligned             -- ^ Argument is not aligned properly.
    | ErrorFalse                  -- ^ Request rejection/false response.
    | ErrorInvalidArgs            -- ^ Invalid function arguments.
    | ErrorOverflow               -- ^ Overflow.
    | ErrorInvalidValue           -- ^ Invalid value.
    | ErrorNotFound                  -- ^ Key not found (IWKV_ERROR_NOTFOUND)
    | ErrorKeyExists                 -- ^ Key already exists (IWKV_ERROR_KEY_EXISTS)
    | ErrorMaxkvsz                   -- ^ Size of Key+value must be not greater than 0xfffffff bytes (IWKV_ERROR_MAXKVSZ)
    | ErrorCorrupted                 -- ^ Database file invalid or corrupted (IWKV_ERROR_CORRUPTED)
    | ErrorDupValueSize              -- ^ Value size is not compatible for insertion into sorted values array (IWKV_ERROR_DUP_VALUE_SIZE)
    | ErrorKeyNumValueSize           -- ^ Given key is not compatible to storage as number (IWKV_ERROR_KEY_NUM_VALUE_SIZE)
    | ErrorIncompatibleDbMode        -- ^ Incorpatible database open mode (IWKV_ERROR_INCOMPATIBLE_DB_MODE)
    | ErrorIncompatibleDbFormat      -- ^ Incompatible database format version, please migrate database data (IWKV_ERROR_INCOMPATIBLE_DB_FORMAT)
    | ErrorCorruptedWalFile          -- ^ Corrupted WAL file (IWKV_ERROR_CORRUPTED_WAL_FILE)
    | ErrorValueCannotBeIncremented  -- ^ Stored value cannot be incremented/descremented (IWKV_ERROR_VALUE_CANNOT_BE_INCREMENTED)
    | ErrorWalModeRequired           -- ^ Operation requires WAL enabled database. (IWKV_ERROR_WAL_MODE_REQUIRED)
    | ErrorBackupInProgress          -- ^ Backup operation in progress. (IWKV_ERROR_BACKUP_IN_PROGRESS)
    | ErrorInvalidBuffer             -- ^ Invalid JBL buffer (JBLERRORINVALIDBUFFER)
    | ErrorCreation                   -- ^ Cannot create JBL object (JBLERRORCREATION)
    | ErrorInvalid                    -- ^ Invalid JBL object (JBLERRORINVALID)
    | ErrorParseJson                 -- ^ Failed to parse JSON string (JBLERRORPARSEJSON)
    | ErrorParseUnquotedString      -- ^ Unquoted JSON string (JBLERRORPARSEUNQUOTEDSTRING)
    | ErrorParseInvalidCodepoint    -- ^ Invalid unicode codepoint/escape sequence (JBLERRORPARSEINVALIDCODEPOINT)
    | ErrorParseInvalidUtf8         -- ^ Invalid utf8 string (JBLERRORPARSEINVALIDUTF8)
    | ErrorJsonPointer               -- ^ Invalid JSON pointer (rfc6901) path (JBLERRORJSONPOINTER)
    | ErrorPathNotFound              -- ^ JSON object not matched the path specified (JBLERRORPATHNOTFOUND)
    | ErrorPatchInvalid              -- ^ Invalid JSON patch specified (JBLERRORPATCHINVALID)
    | ErrorPatchInvalidOp           -- ^ Invalid JSON patch operation specified (JBLERRORPATCHINVALIDOP)
    | ErrorPatchNovalue              -- ^ No value specified in JSON patch (JBLERRORPATCHNOVALUE)
    | ErrorPatchTargetInvalid       -- ^ Could not find target object to set value (JBLERRORPATCHTARGETINVALID)
    | ErrorPatchInvalidValue        -- ^ Invalid value specified by patch (JBLERRORPATCHINVALIDVALUE)
    | ErrorPatchInvalidArrayIndex  -- ^ Invalid array index in JSON patch path (JBLERRORPATCHINVALIDARRAYINDEX)
    | ErrorNotAnObject              -- ^ JBL is not an object (JBLERRORNOTANOBJECT)
    | ErrorPatchTestFailed          -- ^ JSON patch test operation failed (JBLERRORPATCHTESTFAILED)
    | ErrorInvalidCollectionName               -- ^ Invalid collection name
    | ErrorInvalidCollectionMeta               -- ^ Invalid collection metadata
    | ErrorInvalidCollectionIndexMeta               -- ^ Invalid collection index metadata
    | ErrorInvalidIndexMode               -- ^ Invalid index mode specified
    | ErrorMismatchedIndexUniquenessMode               -- ^ Index exists but mismatched uniqueness constraint
    | ErrorUniqueIndexConstraintViolated               -- ^ Unique index constraint violated
    | ErrorCollectionNotFound               -- ^ Collection not found
    | ErrorTargetCollectionExists               -- ^ Target collection exists
    | ErrorPatchJsonNotObject               -- ^ Patch JSON must be an object (map)
    | ErrorQueryParse                   -- ^ Query parsing error (JQL_ERROR_QUERY_PARSE)
    | ErrorInvalidPlaceholder           -- ^ Invalid placeholder position (JQL_ERROR_INVALID_PLACEHOLDER)
    | ErrorUnsetPlaceholder             -- ^ Found unset placeholder (JQL_ERROR_UNSET_PLACEHOLDER)
    | ErrorRegexpInvalid                -- ^ Invalid regular expression (JQL_ERROR_REGEXP_INVALID)
    | ErrorRegexpCharset                -- ^ Invalid regular expression: expected ']' at end of character set (JQL_ERROR_REGEXP_CHARSET)
    | ErrorRegexpSubexp                 -- ^ Invalid regular expression: expected ')' at end of subexpression (JQL_ERROR_REGEXP_SUBEXP)
    | ErrorRegexpSubmatch               -- ^ Invalid regular expression: expected '}' at end of submatch (JQL_ERROR_REGEXP_SUBMATCH)
    | ErrorRegexpEngine                 -- ^ Illegal instruction in compiled regular expression (please report this bug) (JQL_ERROR_REGEXP_ENGINE)
    | ErrorSkipAlreadySet               -- ^ Skip clause already specified (JQL_ERROR_SKIP_ALREADY_SET)
    | ErrorLimitAlreadySet              -- ^ Limit clause already specified (JQL_ERROR_SKIP_ALREADY_SET)
    | ErrorOrderbyMaxLimit              -- ^ Reached max number of asc/desc order clauses: 64 (JQL_ERROR_ORDERBY_MAX_LIMIT)
    | ErrorNoCollection                 -- ^ No collection specified in query (JQL_ERROR_NO_COLLECTION)
    | ErrorInvalidPlaceholderValueType  -- ^ Invalid type of placeholder value (JQL_ERROR_INVALID_PLACEHOLDER_VALUE_TYPE)
    deriving ( Result -> Result -> Bool
(Result -> Result -> Bool)
-> (Result -> Result -> Bool) -> Eq Result
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Result -> Result -> Bool
$c/= :: Result -> Result -> Bool
== :: Result -> Result -> Bool
$c== :: Result -> Result -> Bool
Eq, Int -> Result -> ShowS
[Result] -> ShowS
Result -> String
(Int -> Result -> ShowS)
-> (Result -> String) -> ([Result] -> ShowS) -> Show Result
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Result] -> ShowS
$cshowList :: [Result] -> ShowS
show :: Result -> String
$cshow :: Result -> String
showsPrec :: Int -> Result -> ShowS
$cshowsPrec :: Int -> Result -> ShowS
Show )

decodeRC :: RC -> Result
decodeRC :: RC -> Result
decodeRC rc :: RC
rc = case RC
rc of
  0   ->                    Result
Ok
{-# LINE 102 "src/Database/EJDB2/Result.hsc" #-}
  70000   ->            ErrorFail
{-# LINE 103 "src/Database/EJDB2/Result.hsc" #-}
  70001   ->           ErrorErrno
{-# LINE 104 "src/Database/EJDB2/Result.hsc" #-}
  70002   ->        ErrorIoErrno
{-# LINE 105 "src/Database/EJDB2/Result.hsc" #-}
  70003   ->      ErrorNotExists
{-# LINE 106 "src/Database/EJDB2/Result.hsc" #-}
  70004   ->        ErrorReadonly
{-# LINE 107 "src/Database/EJDB2/Result.hsc" #-}
  70005   ->  ErrorAlreadyOpened
{-# LINE 108 "src/Database/EJDB2/Result.hsc" #-}
  70006   ->       ErrorThreading
{-# LINE 109 "src/Database/EJDB2/Result.hsc" #-}
  70007   -> ErrorThreadingErrno
{-# LINE 110 "src/Database/EJDB2/Result.hsc" #-}
  70008   ->       ErrorAssertion
{-# LINE 111 "src/Database/EJDB2/Result.hsc" #-}
  70009   ->  ErrorInvalidHandle
{-# LINE 112 "src/Database/EJDB2/Result.hsc" #-}
  70010   ->   ErrorOutOfBounds
{-# LINE 113 "src/Database/EJDB2/Result.hsc" #-}
  70011   -> ErrorNotImplemented
{-# LINE 114 "src/Database/EJDB2/Result.hsc" #-}
  70012   ->           ErrorAlloc
{-# LINE 115 "src/Database/EJDB2/Result.hsc" #-}
  70013   ->   ErrorInvalidState
{-# LINE 116 "src/Database/EJDB2/Result.hsc" #-}
  70014   ->     ErrorNotAligned
{-# LINE 117 "src/Database/EJDB2/Result.hsc" #-}
  70015   ->           ErrorFalse
{-# LINE 118 "src/Database/EJDB2/Result.hsc" #-}
  70016   ->    ErrorInvalidArgs
{-# LINE 119 "src/Database/EJDB2/Result.hsc" #-}
  70017   ->        ErrorOverflow
{-# LINE 120 "src/Database/EJDB2/Result.hsc" #-}
  70018   ->   ErrorInvalidValue
{-# LINE 121 "src/Database/EJDB2/Result.hsc" #-}
  75001                     ->  ErrorNotFound
{-# LINE 122 "src/Database/EJDB2/Result.hsc" #-}
  75002                   ->  ErrorKeyExists
{-# LINE 123 "src/Database/EJDB2/Result.hsc" #-}
  75003                      ->  ErrorMaxkvsz
{-# LINE 124 "src/Database/EJDB2/Result.hsc" #-}
  75004                    ->  ErrorCorrupted
{-# LINE 125 "src/Database/EJDB2/Result.hsc" #-}
  75005               ->  ErrorDupValueSize
{-# LINE 126 "src/Database/EJDB2/Result.hsc" #-}
  75006           ->  ErrorKeyNumValueSize
{-# LINE 127 "src/Database/EJDB2/Result.hsc" #-}
  75007         ->  ErrorIncompatibleDbMode
{-# LINE 128 "src/Database/EJDB2/Result.hsc" #-}
  75008       ->  ErrorIncompatibleDbFormat
{-# LINE 129 "src/Database/EJDB2/Result.hsc" #-}
  75009           ->  ErrorCorruptedWalFile
{-# LINE 130 "src/Database/EJDB2/Result.hsc" #-}
  75010  ->  ErrorValueCannotBeIncremented
{-# LINE 131 "src/Database/EJDB2/Result.hsc" #-}
  75011            ->  ErrorWalModeRequired
{-# LINE 132 "src/Database/EJDB2/Result.hsc" #-}
  75012           ->  ErrorBackupInProgress
{-# LINE 133 "src/Database/EJDB2/Result.hsc" #-}
  86001             ->  ErrorInvalidBuffer
{-# LINE 134 "src/Database/EJDB2/Result.hsc" #-}
  86002                   ->  ErrorCreation
{-# LINE 135 "src/Database/EJDB2/Result.hsc" #-}
  86003                    ->  ErrorInvalid
{-# LINE 136 "src/Database/EJDB2/Result.hsc" #-}
  86004                 ->  ErrorParseJson
{-# LINE 137 "src/Database/EJDB2/Result.hsc" #-}
  86005      ->  ErrorParseUnquotedString
{-# LINE 138 "src/Database/EJDB2/Result.hsc" #-}
  86006    ->  ErrorParseInvalidCodepoint
{-# LINE 139 "src/Database/EJDB2/Result.hsc" #-}
  86007         ->  ErrorParseInvalidUtf8
{-# LINE 140 "src/Database/EJDB2/Result.hsc" #-}
  86008               ->  ErrorJsonPointer
{-# LINE 141 "src/Database/EJDB2/Result.hsc" #-}
  86009              ->  ErrorPathNotFound
{-# LINE 142 "src/Database/EJDB2/Result.hsc" #-}
  86010              ->  ErrorPatchInvalid
{-# LINE 143 "src/Database/EJDB2/Result.hsc" #-}
  86011           ->  ErrorPatchInvalidOp
{-# LINE 144 "src/Database/EJDB2/Result.hsc" #-}
  86012              ->  ErrorPatchNovalue
{-# LINE 145 "src/Database/EJDB2/Result.hsc" #-}
  86013       ->  ErrorPatchTargetInvalid
{-# LINE 146 "src/Database/EJDB2/Result.hsc" #-}
  86014        ->  ErrorPatchInvalidValue
{-# LINE 147 "src/Database/EJDB2/Result.hsc" #-}
  86015  ->  ErrorPatchInvalidArrayIndex
{-# LINE 148 "src/Database/EJDB2/Result.hsc" #-}
  86016              ->  ErrorNotAnObject
{-# LINE 149 "src/Database/EJDB2/Result.hsc" #-}
  86018          ->  ErrorPatchTestFailed
{-# LINE 150 "src/Database/EJDB2/Result.hsc" #-}
  85001             ->  ErrorInvalidCollectionName
{-# LINE 151 "src/Database/EJDB2/Result.hsc" #-}
  85002             ->  ErrorInvalidCollectionMeta
{-# LINE 152 "src/Database/EJDB2/Result.hsc" #-}
  85003       ->  ErrorInvalidCollectionIndexMeta
{-# LINE 153 "src/Database/EJDB2/Result.hsc" #-}
  85004                  ->  ErrorInvalidIndexMode
{-# LINE 154 "src/Database/EJDB2/Result.hsc" #-}
  85005    ->  ErrorMismatchedIndexUniquenessMode
{-# LINE 155 "src/Database/EJDB2/Result.hsc" #-}
  85006    ->  ErrorUniqueIndexConstraintViolated
{-# LINE 156 "src/Database/EJDB2/Result.hsc" #-}
  85007                ->  ErrorCollectionNotFound
{-# LINE 157 "src/Database/EJDB2/Result.hsc" #-}
  85008            ->  ErrorTargetCollectionExists
{-# LINE 158 "src/Database/EJDB2/Result.hsc" #-}
  85009               ->  ErrorPatchJsonNotObject
{-# LINE 159 "src/Database/EJDB2/Result.hsc" #-}
  87001                          ->  ErrorQueryParse
{-# LINE 160 "src/Database/EJDB2/Result.hsc" #-}
  87002                  ->  ErrorInvalidPlaceholder
{-# LINE 161 "src/Database/EJDB2/Result.hsc" #-}
  87003                    ->  ErrorUnsetPlaceholder
{-# LINE 162 "src/Database/EJDB2/Result.hsc" #-}
  87004                       ->  ErrorRegexpInvalid
{-# LINE 163 "src/Database/EJDB2/Result.hsc" #-}
  87005                       ->  ErrorRegexpCharset
{-# LINE 164 "src/Database/EJDB2/Result.hsc" #-}
  87006                        ->  ErrorRegexpSubexp
{-# LINE 165 "src/Database/EJDB2/Result.hsc" #-}
  87007                      ->  ErrorRegexpSubmatch
{-# LINE 166 "src/Database/EJDB2/Result.hsc" #-}
  87008                        ->  ErrorRegexpEngine
{-# LINE 167 "src/Database/EJDB2/Result.hsc" #-}
  87009                     ->  ErrorSkipAlreadySet
{-# LINE 168 "src/Database/EJDB2/Result.hsc" #-}
  87010                    ->  ErrorLimitAlreadySet
{-# LINE 169 "src/Database/EJDB2/Result.hsc" #-}
  87011                    ->  ErrorOrderbyMaxLimit
{-# LINE 170 "src/Database/EJDB2/Result.hsc" #-}
  87012                        ->  ErrorNoCollection
{-# LINE 171 "src/Database/EJDB2/Result.hsc" #-}
  87013       ->  ErrorInvalidPlaceholderValueType
{-# LINE 172 "src/Database/EJDB2/Result.hsc" #-}
  _                                                ->  error $ "Database.EJDB2.Bindings.IW.decodeRC " ++ show rc