module TD.Data.Venue
  ( Venue(..)    
  , defaultVenue 
  ) 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 Data.Text as T

data Venue
  = Venue -- ^ Describes a venue
    { Venue -> Maybe Location
location :: Maybe Location.Location -- ^ Venue location; as defined by the sender
    , Venue -> Maybe Text
title    :: Maybe T.Text            -- ^ Venue name; as defined by the sender
    , Venue -> Maybe Text
address  :: Maybe T.Text            -- ^ Venue address; as defined by the sender
    , Venue -> Maybe Text
provider :: Maybe T.Text            -- ^ Provider of the venue database; as defined by the sender. Currently, only "foursquare" and "gplaces" (Google Places) need to be supported
    , Venue -> Maybe Text
_id      :: Maybe T.Text            -- ^ Identifier of the venue in the provider database; as defined by the sender
    , Venue -> Maybe Text
_type    :: Maybe T.Text            -- ^ Type of the venue in the provider database; as defined by the sender
    }
  deriving (Venue -> Venue -> Bool
(Venue -> Venue -> Bool) -> (Venue -> Venue -> Bool) -> Eq Venue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Venue -> Venue -> Bool
== :: Venue -> Venue -> Bool
$c/= :: Venue -> Venue -> Bool
/= :: Venue -> Venue -> Bool
Eq, Int -> Venue -> ShowS
[Venue] -> ShowS
Venue -> String
(Int -> Venue -> ShowS)
-> (Venue -> String) -> ([Venue] -> ShowS) -> Show Venue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Venue -> ShowS
showsPrec :: Int -> Venue -> ShowS
$cshow :: Venue -> String
show :: Venue -> String
$cshowList :: [Venue] -> ShowS
showList :: [Venue] -> ShowS
Show)

instance I.ShortShow Venue where
  shortShow :: Venue -> String
shortShow Venue
    { location :: Venue -> Maybe Location
location = Maybe Location
location_
    , title :: Venue -> Maybe Text
title    = Maybe Text
title_
    , address :: Venue -> Maybe Text
address  = Maybe Text
address_
    , provider :: Venue -> Maybe Text
provider = Maybe Text
provider_
    , _id :: Venue -> Maybe Text
_id      = Maybe Text
_id_
    , _type :: Venue -> Maybe Text
_type    = Maybe Text
_type_
    }
      = String
"Venue"
        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
"title"    String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
        , String
"address"  String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
address_
        , String
"provider" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
provider_
        , String
"_id"      String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_id_
        , String
"_type"    String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_type_
        ]

instance AT.FromJSON Venue where
  parseJSON :: Value -> Parser Venue
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
"venue" -> Value -> Parser Venue
parseVenue Value
v
      String
_       -> Parser Venue
forall a. Monoid a => a
mempty
    
    where
      parseVenue :: A.Value -> AT.Parser Venue
      parseVenue :: Value -> Parser Venue
parseVenue = String -> (Object -> Parser Venue) -> Value -> Parser Venue
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Venue" ((Object -> Parser Venue) -> Value -> Parser Venue)
-> (Object -> Parser Venue) -> Value -> Parser Venue
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 Text
title_    <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"title"
        Maybe Text
address_  <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"address"
        Maybe Text
provider_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"provider"
        Maybe Text
_id_      <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"id"
        Maybe Text
_type_    <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"type"
        Venue -> Parser Venue
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Venue -> Parser Venue) -> Venue -> Parser Venue
forall a b. (a -> b) -> a -> b
$ Venue
          { location :: Maybe Location
location = Maybe Location
location_
          , title :: Maybe Text
title    = Maybe Text
title_
          , address :: Maybe Text
address  = Maybe Text
address_
          , provider :: Maybe Text
provider = Maybe Text
provider_
          , _id :: Maybe Text
_id      = Maybe Text
_id_
          , _type :: Maybe Text
_type    = Maybe Text
_type_
          }
  parseJSON Value
_ = Parser Venue
forall a. Monoid a => a
mempty

instance AT.ToJSON Venue where
  toJSON :: Venue -> Value
toJSON Venue
    { location :: Venue -> Maybe Location
location = Maybe Location
location_
    , title :: Venue -> Maybe Text
title    = Maybe Text
title_
    , address :: Venue -> Maybe Text
address  = Maybe Text
address_
    , provider :: Venue -> Maybe Text
provider = Maybe Text
provider_
    , _id :: Venue -> Maybe Text
_id      = Maybe Text
_id_
    , _type :: Venue -> 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
"venue"
        , Key
"location" Key -> Maybe Location -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Location
location_
        , Key
"title"    Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
title_
        , Key
"address"  Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
address_
        , Key
"provider" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
provider_
        , Key
"id"       Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
_id_
        , 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_
        ]

defaultVenue :: Venue
defaultVenue :: Venue
defaultVenue =
  Venue
    { location :: Maybe Location
location = Maybe Location
forall a. Maybe a
Nothing
    , title :: Maybe Text
title    = Maybe Text
forall a. Maybe a
Nothing
    , address :: Maybe Text
address  = Maybe Text
forall a. Maybe a
Nothing
    , provider :: Maybe Text
provider = Maybe Text
forall a. Maybe a
Nothing
    , _id :: Maybe Text
_id      = Maybe Text
forall a. Maybe a
Nothing
    , _type :: Maybe Text
_type    = Maybe Text
forall a. Maybe a
Nothing
    }