module TD.Data.InputStoryAreas
  ( InputStoryAreas(..)    
  , defaultInputStoryAreas 
  ) 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.InputStoryArea as InputStoryArea

data InputStoryAreas
  = InputStoryAreas -- ^ Contains a list of story areas to be added
    { InputStoryAreas -> Maybe [InputStoryArea]
areas :: Maybe [InputStoryArea.InputStoryArea] -- ^ List of input story areas. Currently, a story can have up to 10 inputStoryAreaTypeLocation, inputStoryAreaTypeFoundVenue, and inputStoryAreaTypePreviousVenue areas, up to getOption("story_suggested_reaction_area_count_max") inputStoryAreaTypeSuggestedReaction areas, up to 1 inputStoryAreaTypeMessage area, up to getOption("story_link_area_count_max") inputStoryAreaTypeLink areas if the current user is a Telegram Premium user, and up to 3 inputStoryAreaTypeWeather areas
    }
  deriving (InputStoryAreas -> InputStoryAreas -> Bool
(InputStoryAreas -> InputStoryAreas -> Bool)
-> (InputStoryAreas -> InputStoryAreas -> Bool)
-> Eq InputStoryAreas
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputStoryAreas -> InputStoryAreas -> Bool
== :: InputStoryAreas -> InputStoryAreas -> Bool
$c/= :: InputStoryAreas -> InputStoryAreas -> Bool
/= :: InputStoryAreas -> InputStoryAreas -> Bool
Eq, Int -> InputStoryAreas -> ShowS
[InputStoryAreas] -> ShowS
InputStoryAreas -> String
(Int -> InputStoryAreas -> ShowS)
-> (InputStoryAreas -> String)
-> ([InputStoryAreas] -> ShowS)
-> Show InputStoryAreas
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputStoryAreas -> ShowS
showsPrec :: Int -> InputStoryAreas -> ShowS
$cshow :: InputStoryAreas -> String
show :: InputStoryAreas -> String
$cshowList :: [InputStoryAreas] -> ShowS
showList :: [InputStoryAreas] -> ShowS
Show)

instance I.ShortShow InputStoryAreas where
  shortShow :: InputStoryAreas -> String
shortShow InputStoryAreas
    { areas :: InputStoryAreas -> Maybe [InputStoryArea]
areas = Maybe [InputStoryArea]
areas_
    }
      = String
"InputStoryAreas"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"areas" String -> Maybe [InputStoryArea] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [InputStoryArea]
areas_
        ]

instance AT.FromJSON InputStoryAreas where
  parseJSON :: Value -> Parser InputStoryAreas
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
"inputStoryAreas" -> Value -> Parser InputStoryAreas
parseInputStoryAreas Value
v
      String
_                 -> Parser InputStoryAreas
forall a. Monoid a => a
mempty
    
    where
      parseInputStoryAreas :: A.Value -> AT.Parser InputStoryAreas
      parseInputStoryAreas :: Value -> Parser InputStoryAreas
parseInputStoryAreas = String
-> (Object -> Parser InputStoryAreas)
-> Value
-> Parser InputStoryAreas
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputStoryAreas" ((Object -> Parser InputStoryAreas)
 -> Value -> Parser InputStoryAreas)
-> (Object -> Parser InputStoryAreas)
-> Value
-> Parser InputStoryAreas
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [InputStoryArea]
areas_ <- Object
o Object -> Key -> Parser (Maybe [InputStoryArea])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"areas"
        InputStoryAreas -> Parser InputStoryAreas
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputStoryAreas -> Parser InputStoryAreas)
-> InputStoryAreas -> Parser InputStoryAreas
forall a b. (a -> b) -> a -> b
$ InputStoryAreas
          { areas :: Maybe [InputStoryArea]
areas = Maybe [InputStoryArea]
areas_
          }
  parseJSON Value
_ = Parser InputStoryAreas
forall a. Monoid a => a
mempty

instance AT.ToJSON InputStoryAreas where
  toJSON :: InputStoryAreas -> Value
toJSON InputStoryAreas
    { areas :: InputStoryAreas -> Maybe [InputStoryArea]
areas = Maybe [InputStoryArea]
areas_
    }
      = [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
"inputStoryAreas"
        , Key
"areas" Key -> Maybe [InputStoryArea] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [InputStoryArea]
areas_
        ]

defaultInputStoryAreas :: InputStoryAreas
defaultInputStoryAreas :: InputStoryAreas
defaultInputStoryAreas =
  InputStoryAreas
    { areas :: Maybe [InputStoryArea]
areas = Maybe [InputStoryArea]
forall a. Maybe a
Nothing
    }