module Network.MPD.Commands.Query (Query, (=?), (<&>), anything) where
import Network.MPD.Commands.Arg
import Network.MPD.Commands.Types
import Data.Monoid
import Data.Semigroup
newtype Query = Query [Match] deriving Show
data Match = Match Metadata Value
instance Show Match where
show (Match meta query) = show meta ++ " \"" ++ toString query ++ "\""
showList xs _ = unwords $ map show xs
instance Monoid Query where
mempty = Query []
Query a `mappend` Query b = Query (a ++ b)
instance Semigroup Query where
(<>) = mappend
instance MPDArg Query where
prep = foldl (<++>) (Args []) . f
where f (Query ms) = map (\(Match m q) -> Args [show m] <++> q) ms
anything :: Query
anything = mempty
(=?) :: Metadata -> Value -> Query
m =? s = Query [Match m s]
infixr 6 <&>
(<&>) :: Query -> Query -> Query
(<&>) = mappend
{-# DEPRECATED (<&>) "will be removed in the next major version of libmpd, use `(<>)` instead" #-}