module Database.Redis.SortedSet
    ( zSetAdd, zSetAddB
    , zSetRemove
    , zSetIncrementBy
    , zSetRank
    , zSetReverseRank
    , zSetRange
    , zSetReverseRange
    , zSetRangeByScore
    , zSetCount
    , zSetCardinality
    , zSetScore
    , zSetRemRangeByRank
    , zSetRemRangeByScore
    {-
    , zSetIntersectStore
    , zSetUnionStore
    -}
    ) where


import           System.IO

import           Database.Redis.Internal


------------------------------------------------------------------------------
-- | ZADD
zSetAdd :: Handle
        -> String  -- ^ key
        -> String  -- ^ score, which can be a string float in Redis
        -> String  -- ^ value
        -> IO (Maybe RedisReply)
zSetAdd h k s m = request h $ map toUTF8 ["ZADD", k, s, m]


-- | ZADD
zSetAddB :: Handle
         -> ByteString  -- ^ key
         -> ByteString  -- ^ score, which can be a string float in Redis
         -> ByteString  -- ^ member
         -> IO (Maybe RedisReply)
zSetAddB h k s m = request h [toUTF8 "ZADD", k, s, m]


------------------------------------------------------------------------------
-- | ZREM
zSetRemove :: Handle
           -> String  -- ^ key
           -> IO (Maybe RedisReply)
zSetRemove h k = request h $ map toUTF8 ["ZREM", k]


------------------------------------------------------------------------------
-- | ZINCRBY
zSetIncrementBy :: Handle
                -> String  -- ^ key
                -> Int     -- ^ amount to increment
                -> String  -- ^ member
                -> IO (Maybe RedisReply)
zSetIncrementBy h k i m = request h $ map toUTF8 ["ZINCRBY", k, show i, m]


------------------------------------------------------------------------------
-- | ZRANK
zSetRank :: Handle
         -> String  -- ^ key
         -> String  -- ^ member
         -> IO (Maybe RedisReply)
zSetRank h k m = request h $ map toUTF8 ["ZRANK", k, m]


------------------------------------------------------------------------------
-- | ZREVRANK
zSetReverseRank :: Handle
                -> String  -- ^ key
                -> String  -- ^ member
                -> IO (Maybe RedisReply)
zSetReverseRank h k m = request h $ map toUTF8 ["ZREVRANK", k, m]


------------------------------------------------------------------------------
-- | ZRANGE (does not yet include WITHSCORES)
zSetRange :: Handle
                -> String   -- ^ key
                -> Int      -- ^ start
                -> Int      -- ^ end
                -> IO (Maybe RedisReply)
zSetRange h k s e = request h $ map toUTF8 ["ZRANGE", k, show s, show e]



------------------------------------------------------------------------------
-- | ZREVRANGE (does not yet include WITHSCORES)
zSetReverseRange :: Handle
                 -> String  -- ^ key
                 -> Int      -- ^ start
                 -> Int      -- ^ end
                 -> IO (Maybe RedisReply)
zSetReverseRange h k s e = request h $ map toUTF8 ["ZREVRANGE", k, show s, show e]


------------------------------------------------------------------------------
-- | ZRANGEBYSCORE
zSetRangeByScore :: Handle
                 -> String   -- ^ key
                 -> Int      -- ^ mn
                 -> Int      -- ^ mx
                 -> IO (Maybe RedisReply)
zSetRangeByScore h k mn mx =
    request h $ map toUTF8 ["ZRANGEBYSCORE", k, show mn, show mx]


------------------------------------------------------------------------------
-- | ZCOUNT
zSetCount :: Handle
          -> String   -- ^ key
          -> Int      -- ^ mn
          -> Int      -- ^ mx
          -> IO (Maybe RedisReply)
zSetCount h k mn mx =
    request h $ map toUTF8 ["ZCOUNT", k, show mn, show mx]


------------------------------------------------------------------------------
-- | ZCARD
zSetCardinality :: Handle
                -> String  -- ^ key
                -> IO (Maybe RedisReply)
zSetCardinality h k = request h $ map toUTF8 ["ZCARD", k]


------------------------------------------------------------------------------
-- | ZSCORE
zSetScore :: Handle
          -> String  -- ^ key
          -> String  -- ^ member
          -> IO (Maybe RedisReply)
zSetScore h k m = request h $ map toUTF8 ["ZSCORE", k, m]


------------------------------------------------------------------------------
-- | ZREMRANGEBYRANK
zSetRemRangeByRank :: Handle
                   -> String  -- ^ key
                   -> String  -- ^ member
                   -> IO (Maybe RedisReply)
zSetRemRangeByRank h k m = request h $ map toUTF8 ["ZREVRANK", k, m]


------------------------------------------------------------------------------
-- | ZREMRANGEBYSCORE
zSetRemRangeByScore :: Handle
                    -> String   -- ^ key
                    -> Int      -- ^ start
                    -> Int      -- ^ end
                    -> IO (Maybe RedisReply)
zSetRemRangeByScore h k s e = request h $ map toUTF8 ["ZREMRANGEBYSCORE", k, show s, show e]

{--
------------------------------------------------------------------------------
-- | ZUNIONSTORE
zSetUnionStore :: Handle
                -> String  -- ^ key
                -> String  -- ^ member
                -> IO (Maybe RedisReply)
zSetUnionStore h k m = request h $ map toUTF8 ["ZUNIONSTORE", k, m]


------------------------------------------------------------------------------
-- | ZINTERSTORE
zSetReverseRank :: Handle
                -> String  -- ^ key
                -> String  -- ^ member
                -> IO (Maybe RedisReply)
zSetReverseRank h k m = request h $ map toUTF8 ["ZREVRANK", k, m]

--}