module Taskwarrior.RecurringChild
( RecurringChild(..)
, parseFromObjectMay
, toPairs
)
where
import Control.Applicative ( optional )
import Data.Aeson ( Object
, (.:)
, (.=)
, ToJSON
, FromJSON
, pairs
, object
, withObject
)
import qualified Data.Aeson as Aeson
import Data.Aeson.Types ( Parser
, Pair
)
import Data.Text ( Text )
import Data.UUID ( UUID )
data RecurringChild =
RecurringChild {
RecurringChild -> Text
recur :: Text,
RecurringChild -> Integer
imask :: Integer,
RecurringChild -> UUID
parent :: UUID }
deriving (RecurringChild -> RecurringChild -> Bool
(RecurringChild -> RecurringChild -> Bool)
-> (RecurringChild -> RecurringChild -> Bool) -> Eq RecurringChild
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RecurringChild -> RecurringChild -> Bool
$c/= :: RecurringChild -> RecurringChild -> Bool
== :: RecurringChild -> RecurringChild -> Bool
$c== :: RecurringChild -> RecurringChild -> Bool
Eq, Int -> RecurringChild -> ShowS
[RecurringChild] -> ShowS
RecurringChild -> String
(Int -> RecurringChild -> ShowS)
-> (RecurringChild -> String)
-> ([RecurringChild] -> ShowS)
-> Show RecurringChild
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecurringChild] -> ShowS
$cshowList :: [RecurringChild] -> ShowS
show :: RecurringChild -> String
$cshow :: RecurringChild -> String
showsPrec :: Int -> RecurringChild -> ShowS
$cshowsPrec :: Int -> RecurringChild -> ShowS
Show, ReadPrec [RecurringChild]
ReadPrec RecurringChild
Int -> ReadS RecurringChild
ReadS [RecurringChild]
(Int -> ReadS RecurringChild)
-> ReadS [RecurringChild]
-> ReadPrec RecurringChild
-> ReadPrec [RecurringChild]
-> Read RecurringChild
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RecurringChild]
$creadListPrec :: ReadPrec [RecurringChild]
readPrec :: ReadPrec RecurringChild
$creadPrec :: ReadPrec RecurringChild
readList :: ReadS [RecurringChild]
$creadList :: ReadS [RecurringChild]
readsPrec :: Int -> ReadS RecurringChild
$creadsPrec :: Int -> ReadS RecurringChild
Read, Eq RecurringChild
Eq RecurringChild
-> (RecurringChild -> RecurringChild -> Ordering)
-> (RecurringChild -> RecurringChild -> Bool)
-> (RecurringChild -> RecurringChild -> Bool)
-> (RecurringChild -> RecurringChild -> Bool)
-> (RecurringChild -> RecurringChild -> Bool)
-> (RecurringChild -> RecurringChild -> RecurringChild)
-> (RecurringChild -> RecurringChild -> RecurringChild)
-> Ord RecurringChild
RecurringChild -> RecurringChild -> Bool
RecurringChild -> RecurringChild -> Ordering
RecurringChild -> RecurringChild -> RecurringChild
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: RecurringChild -> RecurringChild -> RecurringChild
$cmin :: RecurringChild -> RecurringChild -> RecurringChild
max :: RecurringChild -> RecurringChild -> RecurringChild
$cmax :: RecurringChild -> RecurringChild -> RecurringChild
>= :: RecurringChild -> RecurringChild -> Bool
$c>= :: RecurringChild -> RecurringChild -> Bool
> :: RecurringChild -> RecurringChild -> Bool
$c> :: RecurringChild -> RecurringChild -> Bool
<= :: RecurringChild -> RecurringChild -> Bool
$c<= :: RecurringChild -> RecurringChild -> Bool
< :: RecurringChild -> RecurringChild -> Bool
$c< :: RecurringChild -> RecurringChild -> Bool
compare :: RecurringChild -> RecurringChild -> Ordering
$ccompare :: RecurringChild -> RecurringChild -> Ordering
$cp1Ord :: Eq RecurringChild
Ord)
parseFromObjectMay :: Object -> Parser (Maybe RecurringChild)
parseFromObjectMay :: Object -> Parser (Maybe RecurringChild)
parseFromObjectMay = Parser RecurringChild -> Parser (Maybe RecurringChild)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser RecurringChild -> Parser (Maybe RecurringChild))
-> (Object -> Parser RecurringChild)
-> Object
-> Parser (Maybe RecurringChild)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Object -> Parser RecurringChild
parseFromObject
parseFromObject :: Object -> Parser RecurringChild
parseFromObject :: Object -> Parser RecurringChild
parseFromObject Object
o =
Text -> Integer -> UUID -> RecurringChild
RecurringChild (Text -> Integer -> UUID -> RecurringChild)
-> Parser Text -> Parser (Integer -> UUID -> RecurringChild)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"recur" Parser (Integer -> UUID -> RecurringChild)
-> Parser Integer -> Parser (UUID -> RecurringChild)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Text -> Parser Integer
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"imask" Parser (UUID -> RecurringChild)
-> Parser UUID -> Parser RecurringChild
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Text -> Parser UUID
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"parent"
toPairs :: RecurringChild -> [Pair]
toPairs :: RecurringChild -> [Pair]
toPairs RecurringChild {Integer
Text
UUID
parent :: UUID
imask :: Integer
recur :: Text
parent :: RecurringChild -> UUID
imask :: RecurringChild -> Integer
recur :: RecurringChild -> Text
..} =
[Text
"recur" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Text
recur, Text
"imask" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Integer
imask, Text
"parent" Text -> UUID -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= UUID
parent]
instance FromJSON RecurringChild where
parseJSON :: Value -> Parser RecurringChild
parseJSON = String
-> (Object -> Parser RecurringChild)
-> Value
-> Parser RecurringChild
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"RecurringChild" Object -> Parser RecurringChild
parseFromObject
instance ToJSON RecurringChild where
toJSON :: RecurringChild -> Value
toJSON = [Pair] -> Value
object ([Pair] -> Value)
-> (RecurringChild -> [Pair]) -> RecurringChild -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RecurringChild -> [Pair]
toPairs
toEncoding :: RecurringChild -> Encoding
toEncoding = Series -> Encoding
pairs (Series -> Encoding)
-> (RecurringChild -> Series) -> RecurringChild -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Series] -> Series
forall a. Monoid a => [a] -> a
mconcat ([Series] -> Series)
-> (RecurringChild -> [Series]) -> RecurringChild -> Series
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Pair -> Series) -> [Pair] -> [Series]
forall a b. (a -> b) -> [a] -> [b]
map ((Text -> Value -> Series) -> Pair -> Series
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Text -> Value -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
(.=)) ([Pair] -> [Series])
-> (RecurringChild -> [Pair]) -> RecurringChild -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RecurringChild -> [Pair]
toPairs