module TD.Data.InputChecklist
  ( InputChecklist(..)    
  , defaultInputChecklist 
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.FormattedText as FormattedText
import qualified TD.Data.InputChecklistTask as InputChecklistTask

data InputChecklist
  = InputChecklist -- ^ Describes a checklist to be sent
    { InputChecklist -> Maybe FormattedText
title                         :: Maybe FormattedText.FormattedText             -- ^ Title of the checklist; 1-getOption("checklist_title_length_max") characters. May contain only Bold, Italic, Underline, Strikethrough, Spoiler, and CustomEmoji entities
    , InputChecklist -> Maybe [InputChecklistTask]
tasks                         :: Maybe [InputChecklistTask.InputChecklistTask] -- ^ List of tasks in the checklist; 1-getOption("checklist_task_count_max") tasks
    , InputChecklist -> Maybe Bool
others_can_add_tasks          :: Maybe Bool                                    -- ^ True, if other users can add tasks to the list
    , InputChecklist -> Maybe Bool
others_can_mark_tasks_as_done :: Maybe Bool                                    -- ^ True, if other users can mark tasks as done or not done
    }
  deriving (InputChecklist -> InputChecklist -> Bool
(InputChecklist -> InputChecklist -> Bool)
-> (InputChecklist -> InputChecklist -> Bool) -> Eq InputChecklist
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputChecklist -> InputChecklist -> Bool
== :: InputChecklist -> InputChecklist -> Bool
$c/= :: InputChecklist -> InputChecklist -> Bool
/= :: InputChecklist -> InputChecklist -> Bool
Eq, Int -> InputChecklist -> ShowS
[InputChecklist] -> ShowS
InputChecklist -> String
(Int -> InputChecklist -> ShowS)
-> (InputChecklist -> String)
-> ([InputChecklist] -> ShowS)
-> Show InputChecklist
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputChecklist -> ShowS
showsPrec :: Int -> InputChecklist -> ShowS
$cshow :: InputChecklist -> String
show :: InputChecklist -> String
$cshowList :: [InputChecklist] -> ShowS
showList :: [InputChecklist] -> ShowS
Show)

instance I.ShortShow InputChecklist where
  shortShow :: InputChecklist -> String
shortShow InputChecklist
    { title :: InputChecklist -> Maybe FormattedText
title                         = Maybe FormattedText
title_
    , tasks :: InputChecklist -> Maybe [InputChecklistTask]
tasks                         = Maybe [InputChecklistTask]
tasks_
    , others_can_add_tasks :: InputChecklist -> Maybe Bool
others_can_add_tasks          = Maybe Bool
others_can_add_tasks_
    , others_can_mark_tasks_as_done :: InputChecklist -> Maybe Bool
others_can_mark_tasks_as_done = Maybe Bool
others_can_mark_tasks_as_done_
    }
      = String
"InputChecklist"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"title"                         String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
title_
        , String
"tasks"                         String -> Maybe [InputChecklistTask] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [InputChecklistTask]
tasks_
        , String
"others_can_add_tasks"          String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
others_can_add_tasks_
        , String
"others_can_mark_tasks_as_done" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
others_can_mark_tasks_as_done_
        ]

instance AT.FromJSON InputChecklist where
  parseJSON :: Value -> Parser InputChecklist
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
"inputChecklist" -> Value -> Parser InputChecklist
parseInputChecklist Value
v
      String
_                -> Parser InputChecklist
forall a. Monoid a => a
mempty
    
    where
      parseInputChecklist :: A.Value -> AT.Parser InputChecklist
      parseInputChecklist :: Value -> Parser InputChecklist
parseInputChecklist = String
-> (Object -> Parser InputChecklist)
-> Value
-> Parser InputChecklist
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputChecklist" ((Object -> Parser InputChecklist)
 -> Value -> Parser InputChecklist)
-> (Object -> Parser InputChecklist)
-> Value
-> Parser InputChecklist
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe FormattedText
title_                         <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"title"
        Maybe [InputChecklistTask]
tasks_                         <- Object
o Object -> Key -> Parser (Maybe [InputChecklistTask])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"tasks"
        Maybe Bool
others_can_add_tasks_          <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"others_can_add_tasks"
        Maybe Bool
others_can_mark_tasks_as_done_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"others_can_mark_tasks_as_done"
        InputChecklist -> Parser InputChecklist
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputChecklist -> Parser InputChecklist)
-> InputChecklist -> Parser InputChecklist
forall a b. (a -> b) -> a -> b
$ InputChecklist
          { title :: Maybe FormattedText
title                         = Maybe FormattedText
title_
          , tasks :: Maybe [InputChecklistTask]
tasks                         = Maybe [InputChecklistTask]
tasks_
          , others_can_add_tasks :: Maybe Bool
others_can_add_tasks          = Maybe Bool
others_can_add_tasks_
          , others_can_mark_tasks_as_done :: Maybe Bool
others_can_mark_tasks_as_done = Maybe Bool
others_can_mark_tasks_as_done_
          }
  parseJSON Value
_ = Parser InputChecklist
forall a. Monoid a => a
mempty

instance AT.ToJSON InputChecklist where
  toJSON :: InputChecklist -> Value
toJSON InputChecklist
    { title :: InputChecklist -> Maybe FormattedText
title                         = Maybe FormattedText
title_
    , tasks :: InputChecklist -> Maybe [InputChecklistTask]
tasks                         = Maybe [InputChecklistTask]
tasks_
    , others_can_add_tasks :: InputChecklist -> Maybe Bool
others_can_add_tasks          = Maybe Bool
others_can_add_tasks_
    , others_can_mark_tasks_as_done :: InputChecklist -> Maybe Bool
others_can_mark_tasks_as_done = Maybe Bool
others_can_mark_tasks_as_done_
    }
      = [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
"inputChecklist"
        , Key
"title"                         Key -> Maybe FormattedText -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe FormattedText
title_
        , Key
"tasks"                         Key -> Maybe [InputChecklistTask] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [InputChecklistTask]
tasks_
        , Key
"others_can_add_tasks"          Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
others_can_add_tasks_
        , Key
"others_can_mark_tasks_as_done" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
others_can_mark_tasks_as_done_
        ]

defaultInputChecklist :: InputChecklist
defaultInputChecklist :: InputChecklist
defaultInputChecklist =
  InputChecklist
    { title :: Maybe FormattedText
title                         = Maybe FormattedText
forall a. Maybe a
Nothing
    , tasks :: Maybe [InputChecklistTask]
tasks                         = Maybe [InputChecklistTask]
forall a. Maybe a
Nothing
    , others_can_add_tasks :: Maybe Bool
others_can_add_tasks          = Maybe Bool
forall a. Maybe a
Nothing
    , others_can_mark_tasks_as_done :: Maybe Bool
others_can_mark_tasks_as_done = Maybe Bool
forall a. Maybe a
Nothing
    }