module TD.Data.PageBlockListItem
  ( PageBlockListItem(..)    
  , defaultPageBlockListItem 
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
import {-# SOURCE #-} qualified TD.Data.PageBlock as PageBlock

data PageBlockListItem
  = PageBlockListItem -- ^ Describes an item of a list page block
    { PageBlockListItem -> Maybe Text
label        :: Maybe T.Text                -- ^ Item label
    , PageBlockListItem -> Maybe [PageBlock]
blocks       :: Maybe [PageBlock.PageBlock] -- ^ Item blocks
    , PageBlockListItem -> Maybe Bool
has_checkbox :: Maybe Bool                  -- ^ True, if the item has a checkbox
    , PageBlockListItem -> Maybe Bool
is_checked   :: Maybe Bool                  -- ^ True, if the item is checked
    , PageBlockListItem -> Maybe Int
value        :: Maybe Int                   -- ^ Value of the item; 0 for unordered lists
    , PageBlockListItem -> Maybe Text
_type        :: Maybe T.Text                -- ^ Type of the item numbering type; must be one of "a" for lowercase letters, "A" for uppercase letters, "i" for lowercase Roman numerals, "I" for uppercase Roman numerals, "1" for decimal numbers, or empty for unordered lists
    }
  deriving (PageBlockListItem -> PageBlockListItem -> Bool
(PageBlockListItem -> PageBlockListItem -> Bool)
-> (PageBlockListItem -> PageBlockListItem -> Bool)
-> Eq PageBlockListItem
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PageBlockListItem -> PageBlockListItem -> Bool
== :: PageBlockListItem -> PageBlockListItem -> Bool
$c/= :: PageBlockListItem -> PageBlockListItem -> Bool
/= :: PageBlockListItem -> PageBlockListItem -> Bool
Eq, Int -> PageBlockListItem -> ShowS
[PageBlockListItem] -> ShowS
PageBlockListItem -> String
(Int -> PageBlockListItem -> ShowS)
-> (PageBlockListItem -> String)
-> ([PageBlockListItem] -> ShowS)
-> Show PageBlockListItem
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PageBlockListItem -> ShowS
showsPrec :: Int -> PageBlockListItem -> ShowS
$cshow :: PageBlockListItem -> String
show :: PageBlockListItem -> String
$cshowList :: [PageBlockListItem] -> ShowS
showList :: [PageBlockListItem] -> ShowS
Show)

instance I.ShortShow PageBlockListItem where
  shortShow :: PageBlockListItem -> String
shortShow PageBlockListItem
    { label :: PageBlockListItem -> Maybe Text
label        = Maybe Text
label_
    , blocks :: PageBlockListItem -> Maybe [PageBlock]
blocks       = Maybe [PageBlock]
blocks_
    , has_checkbox :: PageBlockListItem -> Maybe Bool
has_checkbox = Maybe Bool
has_checkbox_
    , is_checked :: PageBlockListItem -> Maybe Bool
is_checked   = Maybe Bool
is_checked_
    , value :: PageBlockListItem -> Maybe Int
value        = Maybe Int
value_
    , _type :: PageBlockListItem -> Maybe Text
_type        = Maybe Text
_type_
    }
      = String
"PageBlockListItem"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"label"        String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
label_
        , String
"blocks"       String -> Maybe [PageBlock] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [PageBlock]
blocks_
        , String
"has_checkbox" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_checkbox_
        , String
"is_checked"   String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_checked_
        , String
"value"        String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
value_
        , String
"_type"        String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_type_
        ]

instance AT.FromJSON PageBlockListItem where
  parseJSON :: Value -> Parser PageBlockListItem
parseJSON v :: Value
v@(AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"pageBlockListItem" -> Value -> Parser PageBlockListItem
parsePageBlockListItem Value
v
      String
_                   -> Parser PageBlockListItem
forall a. Monoid a => a
mempty
    
    where
      parsePageBlockListItem :: A.Value -> AT.Parser PageBlockListItem
      parsePageBlockListItem :: Value -> Parser PageBlockListItem
parsePageBlockListItem = String
-> (Object -> Parser PageBlockListItem)
-> Value
-> Parser PageBlockListItem
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PageBlockListItem" ((Object -> Parser PageBlockListItem)
 -> Value -> Parser PageBlockListItem)
-> (Object -> Parser PageBlockListItem)
-> Value
-> Parser PageBlockListItem
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
label_        <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"label"
        Maybe [PageBlock]
blocks_       <- Object
o Object -> Key -> Parser (Maybe [PageBlock])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"blocks"
        Maybe Bool
has_checkbox_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"has_checkbox"
        Maybe Bool
is_checked_   <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_checked"
        Maybe Int
value_        <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"value"
        Maybe Text
_type_        <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"type"
        PageBlockListItem -> Parser PageBlockListItem
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PageBlockListItem -> Parser PageBlockListItem)
-> PageBlockListItem -> Parser PageBlockListItem
forall a b. (a -> b) -> a -> b
$ PageBlockListItem
          { label :: Maybe Text
label        = Maybe Text
label_
          , blocks :: Maybe [PageBlock]
blocks       = Maybe [PageBlock]
blocks_
          , has_checkbox :: Maybe Bool
has_checkbox = Maybe Bool
has_checkbox_
          , is_checked :: Maybe Bool
is_checked   = Maybe Bool
is_checked_
          , value :: Maybe Int
value        = Maybe Int
value_
          , _type :: Maybe Text
_type        = Maybe Text
_type_
          }
  parseJSON Value
_ = Parser PageBlockListItem
forall a. Monoid a => a
mempty

instance AT.ToJSON PageBlockListItem where
  toJSON :: PageBlockListItem -> Value
toJSON PageBlockListItem
    { label :: PageBlockListItem -> Maybe Text
label        = Maybe Text
label_
    , blocks :: PageBlockListItem -> Maybe [PageBlock]
blocks       = Maybe [PageBlock]
blocks_
    , has_checkbox :: PageBlockListItem -> Maybe Bool
has_checkbox = Maybe Bool
has_checkbox_
    , is_checked :: PageBlockListItem -> Maybe Bool
is_checked   = Maybe Bool
is_checked_
    , value :: PageBlockListItem -> Maybe Int
value        = Maybe Int
value_
    , _type :: PageBlockListItem -> Maybe Text
_type        = Maybe Text
_type_
    }
      = [Pair] -> Value
A.object
        [ Key
"@type"        Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"pageBlockListItem"
        , Key
"label"        Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
label_
        , Key
"blocks"       Key -> Maybe [PageBlock] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [PageBlock]
blocks_
        , Key
"has_checkbox" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
has_checkbox_
        , Key
"is_checked"   Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_checked_
        , Key
"value"        Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
value_
        , Key
"type"         Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
_type_
        ]

defaultPageBlockListItem :: PageBlockListItem
defaultPageBlockListItem :: PageBlockListItem
defaultPageBlockListItem =
  PageBlockListItem
    { label :: Maybe Text
label        = Maybe Text
forall a. Maybe a
Nothing
    , blocks :: Maybe [PageBlock]
blocks       = Maybe [PageBlock]
forall a. Maybe a
Nothing
    , has_checkbox :: Maybe Bool
has_checkbox = Maybe Bool
forall a. Maybe a
Nothing
    , is_checked :: Maybe Bool
is_checked   = Maybe Bool
forall a. Maybe a
Nothing
    , value :: Maybe Int
value        = Maybe Int
forall a. Maybe a
Nothing
    , _type :: Maybe Text
_type        = Maybe Text
forall a. Maybe a
Nothing
    }