module TD.Data.StoryAreaType
  (StoryAreaType(..)) 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.Location as Location
import qualified TD.Data.LocationAddress as LocationAddress
import qualified TD.Data.Venue as Venue
import qualified TD.Data.ReactionType as ReactionType
import qualified Data.Text as T

-- | Describes type of clickable area on a story media
data StoryAreaType
  = StoryAreaTypeLocation -- ^ An area pointing to a location
    { StoryAreaType -> Maybe Location
location :: Maybe Location.Location               -- ^ The location
    , StoryAreaType -> Maybe LocationAddress
address  :: Maybe LocationAddress.LocationAddress -- ^ Address of the location; may be null if unknown
    }
  | StoryAreaTypeVenue -- ^ An area pointing to a venue
    { StoryAreaType -> Maybe Venue
venue :: Maybe Venue.Venue -- ^ Information about the venue
    }
  | StoryAreaTypeSuggestedReaction -- ^ An area pointing to a suggested reaction. App needs to show a clickable reaction on the area and call setStoryReaction when the are is clicked
    { StoryAreaType -> Maybe ReactionType
reaction_type :: Maybe ReactionType.ReactionType -- ^ Type of the reaction
    , StoryAreaType -> Maybe Int
total_count   :: Maybe Int                       -- ^ Number of times the reaction was added
    , StoryAreaType -> Maybe Bool
is_dark       :: Maybe Bool                      -- ^ True, if reaction has a dark background
    , StoryAreaType -> Maybe Bool
is_flipped    :: Maybe Bool                      -- ^ True, if reaction corner is flipped
    }
  | StoryAreaTypeMessage -- ^ An area pointing to a message
    { StoryAreaType -> Maybe Int
chat_id    :: Maybe Int -- ^ Identifier of the chat with the message
    , StoryAreaType -> Maybe Int
message_id :: Maybe Int -- ^ Identifier of the message
    }
  | StoryAreaTypeLink -- ^ An area pointing to a HTTP or tg:// link
    { StoryAreaType -> Maybe Text
url :: Maybe T.Text -- ^ HTTP or tg:// URL to be opened when the area is clicked
    }
  | StoryAreaTypeWeather -- ^ An area with information about weather
    { StoryAreaType -> Maybe Double
temperature      :: Maybe Double -- ^ Temperature, in degree Celsius
    , StoryAreaType -> Maybe Text
emoji            :: Maybe T.Text -- ^ Emoji representing the weather
    , StoryAreaType -> Maybe Int
background_color :: Maybe Int    -- ^ A color of the area background in the ARGB format
    }
  deriving (StoryAreaType -> StoryAreaType -> Bool
(StoryAreaType -> StoryAreaType -> Bool)
-> (StoryAreaType -> StoryAreaType -> Bool) -> Eq StoryAreaType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StoryAreaType -> StoryAreaType -> Bool
== :: StoryAreaType -> StoryAreaType -> Bool
$c/= :: StoryAreaType -> StoryAreaType -> Bool
/= :: StoryAreaType -> StoryAreaType -> Bool
Eq, Int -> StoryAreaType -> ShowS
[StoryAreaType] -> ShowS
StoryAreaType -> String
(Int -> StoryAreaType -> ShowS)
-> (StoryAreaType -> String)
-> ([StoryAreaType] -> ShowS)
-> Show StoryAreaType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StoryAreaType -> ShowS
showsPrec :: Int -> StoryAreaType -> ShowS
$cshow :: StoryAreaType -> String
show :: StoryAreaType -> String
$cshowList :: [StoryAreaType] -> ShowS
showList :: [StoryAreaType] -> ShowS
Show)

instance I.ShortShow StoryAreaType where
  shortShow :: StoryAreaType -> String
shortShow StoryAreaTypeLocation
    { location :: StoryAreaType -> Maybe Location
location = Maybe Location
location_
    , address :: StoryAreaType -> Maybe LocationAddress
address  = Maybe LocationAddress
address_
    }
      = String
"StoryAreaTypeLocation"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"location" String -> Maybe Location -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Location
location_
        , String
"address"  String -> Maybe LocationAddress -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe LocationAddress
address_
        ]
  shortShow StoryAreaTypeVenue
    { venue :: StoryAreaType -> Maybe Venue
venue = Maybe Venue
venue_
    }
      = String
"StoryAreaTypeVenue"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"venue" String -> Maybe Venue -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Venue
venue_
        ]
  shortShow StoryAreaTypeSuggestedReaction
    { reaction_type :: StoryAreaType -> Maybe ReactionType
reaction_type = Maybe ReactionType
reaction_type_
    , total_count :: StoryAreaType -> Maybe Int
total_count   = Maybe Int
total_count_
    , is_dark :: StoryAreaType -> Maybe Bool
is_dark       = Maybe Bool
is_dark_
    , is_flipped :: StoryAreaType -> Maybe Bool
is_flipped    = Maybe Bool
is_flipped_
    }
      = String
"StoryAreaTypeSuggestedReaction"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"reaction_type" String -> Maybe ReactionType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ReactionType
reaction_type_
        , String
"total_count"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_count_
        , String
"is_dark"       String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_dark_
        , String
"is_flipped"    String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_flipped_
        ]
  shortShow StoryAreaTypeMessage
    { chat_id :: StoryAreaType -> Maybe Int
chat_id    = Maybe Int
chat_id_
    , message_id :: StoryAreaType -> Maybe Int
message_id = Maybe Int
message_id_
    }
      = String
"StoryAreaTypeMessage"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"chat_id"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
        , String
"message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_id_
        ]
  shortShow StoryAreaTypeLink
    { url :: StoryAreaType -> Maybe Text
url = Maybe Text
url_
    }
      = String
"StoryAreaTypeLink"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"url" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
        ]
  shortShow StoryAreaTypeWeather
    { temperature :: StoryAreaType -> Maybe Double
temperature      = Maybe Double
temperature_
    , emoji :: StoryAreaType -> Maybe Text
emoji            = Maybe Text
emoji_
    , background_color :: StoryAreaType -> Maybe Int
background_color = Maybe Int
background_color_
    }
      = String
"StoryAreaTypeWeather"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"temperature"      String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
temperature_
        , String
"emoji"            String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
emoji_
        , String
"background_color" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
background_color_
        ]

instance AT.FromJSON StoryAreaType where
  parseJSON :: Value -> Parser StoryAreaType
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
"storyAreaTypeLocation"          -> Value -> Parser StoryAreaType
parseStoryAreaTypeLocation Value
v
      String
"storyAreaTypeVenue"             -> Value -> Parser StoryAreaType
parseStoryAreaTypeVenue Value
v
      String
"storyAreaTypeSuggestedReaction" -> Value -> Parser StoryAreaType
parseStoryAreaTypeSuggestedReaction Value
v
      String
"storyAreaTypeMessage"           -> Value -> Parser StoryAreaType
parseStoryAreaTypeMessage Value
v
      String
"storyAreaTypeLink"              -> Value -> Parser StoryAreaType
parseStoryAreaTypeLink Value
v
      String
"storyAreaTypeWeather"           -> Value -> Parser StoryAreaType
parseStoryAreaTypeWeather Value
v
      String
_                                -> Parser StoryAreaType
forall a. Monoid a => a
mempty
    
    where
      parseStoryAreaTypeLocation :: A.Value -> AT.Parser StoryAreaType
      parseStoryAreaTypeLocation :: Value -> Parser StoryAreaType
parseStoryAreaTypeLocation = String
-> (Object -> Parser StoryAreaType)
-> Value
-> Parser StoryAreaType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StoryAreaTypeLocation" ((Object -> Parser StoryAreaType) -> Value -> Parser StoryAreaType)
-> (Object -> Parser StoryAreaType)
-> Value
-> Parser StoryAreaType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Location
location_ <- Object
o Object -> Key -> Parser (Maybe Location)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"location"
        Maybe LocationAddress
address_  <- Object
o Object -> Key -> Parser (Maybe LocationAddress)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"address"
        StoryAreaType -> Parser StoryAreaType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StoryAreaType -> Parser StoryAreaType)
-> StoryAreaType -> Parser StoryAreaType
forall a b. (a -> b) -> a -> b
$ StoryAreaTypeLocation
          { location :: Maybe Location
location = Maybe Location
location_
          , address :: Maybe LocationAddress
address  = Maybe LocationAddress
address_
          }
      parseStoryAreaTypeVenue :: A.Value -> AT.Parser StoryAreaType
      parseStoryAreaTypeVenue :: Value -> Parser StoryAreaType
parseStoryAreaTypeVenue = String
-> (Object -> Parser StoryAreaType)
-> Value
-> Parser StoryAreaType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StoryAreaTypeVenue" ((Object -> Parser StoryAreaType) -> Value -> Parser StoryAreaType)
-> (Object -> Parser StoryAreaType)
-> Value
-> Parser StoryAreaType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Venue
venue_ <- Object
o Object -> Key -> Parser (Maybe Venue)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"venue"
        StoryAreaType -> Parser StoryAreaType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StoryAreaType -> Parser StoryAreaType)
-> StoryAreaType -> Parser StoryAreaType
forall a b. (a -> b) -> a -> b
$ StoryAreaTypeVenue
          { venue :: Maybe Venue
venue = Maybe Venue
venue_
          }
      parseStoryAreaTypeSuggestedReaction :: A.Value -> AT.Parser StoryAreaType
      parseStoryAreaTypeSuggestedReaction :: Value -> Parser StoryAreaType
parseStoryAreaTypeSuggestedReaction = String
-> (Object -> Parser StoryAreaType)
-> Value
-> Parser StoryAreaType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StoryAreaTypeSuggestedReaction" ((Object -> Parser StoryAreaType) -> Value -> Parser StoryAreaType)
-> (Object -> Parser StoryAreaType)
-> Value
-> Parser StoryAreaType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe ReactionType
reaction_type_ <- Object
o Object -> Key -> Parser (Maybe ReactionType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"reaction_type"
        Maybe Int
total_count_   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"total_count"
        Maybe Bool
is_dark_       <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_dark"
        Maybe Bool
is_flipped_    <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"is_flipped"
        StoryAreaType -> Parser StoryAreaType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StoryAreaType -> Parser StoryAreaType)
-> StoryAreaType -> Parser StoryAreaType
forall a b. (a -> b) -> a -> b
$ StoryAreaTypeSuggestedReaction
          { reaction_type :: Maybe ReactionType
reaction_type = Maybe ReactionType
reaction_type_
          , total_count :: Maybe Int
total_count   = Maybe Int
total_count_
          , is_dark :: Maybe Bool
is_dark       = Maybe Bool
is_dark_
          , is_flipped :: Maybe Bool
is_flipped    = Maybe Bool
is_flipped_
          }
      parseStoryAreaTypeMessage :: A.Value -> AT.Parser StoryAreaType
      parseStoryAreaTypeMessage :: Value -> Parser StoryAreaType
parseStoryAreaTypeMessage = String
-> (Object -> Parser StoryAreaType)
-> Value
-> Parser StoryAreaType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StoryAreaTypeMessage" ((Object -> Parser StoryAreaType) -> Value -> Parser StoryAreaType)
-> (Object -> Parser StoryAreaType)
-> Value
-> Parser StoryAreaType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
chat_id_    <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"chat_id"
        Maybe Int
message_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"message_id"
        StoryAreaType -> Parser StoryAreaType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StoryAreaType -> Parser StoryAreaType)
-> StoryAreaType -> Parser StoryAreaType
forall a b. (a -> b) -> a -> b
$ StoryAreaTypeMessage
          { chat_id :: Maybe Int
chat_id    = Maybe Int
chat_id_
          , message_id :: Maybe Int
message_id = Maybe Int
message_id_
          }
      parseStoryAreaTypeLink :: A.Value -> AT.Parser StoryAreaType
      parseStoryAreaTypeLink :: Value -> Parser StoryAreaType
parseStoryAreaTypeLink = String
-> (Object -> Parser StoryAreaType)
-> Value
-> Parser StoryAreaType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StoryAreaTypeLink" ((Object -> Parser StoryAreaType) -> Value -> Parser StoryAreaType)
-> (Object -> Parser StoryAreaType)
-> Value
-> Parser StoryAreaType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
url_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"url"
        StoryAreaType -> Parser StoryAreaType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StoryAreaType -> Parser StoryAreaType)
-> StoryAreaType -> Parser StoryAreaType
forall a b. (a -> b) -> a -> b
$ StoryAreaTypeLink
          { url :: Maybe Text
url = Maybe Text
url_
          }
      parseStoryAreaTypeWeather :: A.Value -> AT.Parser StoryAreaType
      parseStoryAreaTypeWeather :: Value -> Parser StoryAreaType
parseStoryAreaTypeWeather = String
-> (Object -> Parser StoryAreaType)
-> Value
-> Parser StoryAreaType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StoryAreaTypeWeather" ((Object -> Parser StoryAreaType) -> Value -> Parser StoryAreaType)
-> (Object -> Parser StoryAreaType)
-> Value
-> Parser StoryAreaType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Double
temperature_      <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"temperature"
        Maybe Text
emoji_            <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"emoji"
        Maybe Int
background_color_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"background_color"
        StoryAreaType -> Parser StoryAreaType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StoryAreaType -> Parser StoryAreaType)
-> StoryAreaType -> Parser StoryAreaType
forall a b. (a -> b) -> a -> b
$ StoryAreaTypeWeather
          { temperature :: Maybe Double
temperature      = Maybe Double
temperature_
          , emoji :: Maybe Text
emoji            = Maybe Text
emoji_
          , background_color :: Maybe Int
background_color = Maybe Int
background_color_
          }
  parseJSON Value
_ = Parser StoryAreaType
forall a. Monoid a => a
mempty