module TD.Data.TimeZones
  (TimeZones(..)) 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.TimeZone as TimeZone

data TimeZones
  = TimeZones -- ^ Contains a list of time zones
    { TimeZones -> Maybe [TimeZone]
time_zones :: Maybe [TimeZone.TimeZone] -- ^ A list of time zones
    }
  deriving (TimeZones -> TimeZones -> Bool
(TimeZones -> TimeZones -> Bool)
-> (TimeZones -> TimeZones -> Bool) -> Eq TimeZones
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TimeZones -> TimeZones -> Bool
== :: TimeZones -> TimeZones -> Bool
$c/= :: TimeZones -> TimeZones -> Bool
/= :: TimeZones -> TimeZones -> Bool
Eq, Int -> TimeZones -> ShowS
[TimeZones] -> ShowS
TimeZones -> String
(Int -> TimeZones -> ShowS)
-> (TimeZones -> String)
-> ([TimeZones] -> ShowS)
-> Show TimeZones
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TimeZones -> ShowS
showsPrec :: Int -> TimeZones -> ShowS
$cshow :: TimeZones -> String
show :: TimeZones -> String
$cshowList :: [TimeZones] -> ShowS
showList :: [TimeZones] -> ShowS
Show)

instance I.ShortShow TimeZones where
  shortShow :: TimeZones -> String
shortShow TimeZones
    { time_zones :: TimeZones -> Maybe [TimeZone]
time_zones = Maybe [TimeZone]
time_zones_
    }
      = String
"TimeZones"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"time_zones" String -> Maybe [TimeZone] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [TimeZone]
time_zones_
        ]

instance AT.FromJSON TimeZones where
  parseJSON :: Value -> Parser TimeZones
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
"timeZones" -> Value -> Parser TimeZones
parseTimeZones Value
v
      String
_           -> Parser TimeZones
forall a. Monoid a => a
mempty
    
    where
      parseTimeZones :: A.Value -> AT.Parser TimeZones
      parseTimeZones :: Value -> Parser TimeZones
parseTimeZones = String -> (Object -> Parser TimeZones) -> Value -> Parser TimeZones
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TimeZones" ((Object -> Parser TimeZones) -> Value -> Parser TimeZones)
-> (Object -> Parser TimeZones) -> Value -> Parser TimeZones
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [TimeZone]
time_zones_ <- Object
o Object -> Key -> Parser (Maybe [TimeZone])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"time_zones"
        TimeZones -> Parser TimeZones
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TimeZones -> Parser TimeZones) -> TimeZones -> Parser TimeZones
forall a b. (a -> b) -> a -> b
$ TimeZones
          { time_zones :: Maybe [TimeZone]
time_zones = Maybe [TimeZone]
time_zones_
          }
  parseJSON Value
_ = Parser TimeZones
forall a. Monoid a => a
mempty