module TD.Data.AutoDownloadSettingsPresets
  (AutoDownloadSettingsPresets(..)) 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.AutoDownloadSettings as AutoDownloadSettings

data AutoDownloadSettingsPresets
  = AutoDownloadSettingsPresets -- ^ Contains auto-download settings presets for the current user
    { AutoDownloadSettingsPresets -> Maybe AutoDownloadSettings
low    :: Maybe AutoDownloadSettings.AutoDownloadSettings -- ^ Preset with lowest settings; expected to be used by default when roaming
    , AutoDownloadSettingsPresets -> Maybe AutoDownloadSettings
medium :: Maybe AutoDownloadSettings.AutoDownloadSettings -- ^ Preset with medium settings; expected to be used by default when using mobile data
    , AutoDownloadSettingsPresets -> Maybe AutoDownloadSettings
high   :: Maybe AutoDownloadSettings.AutoDownloadSettings -- ^ Preset with highest settings; expected to be used by default when connected on Wi-Fi
    }
  deriving (AutoDownloadSettingsPresets -> AutoDownloadSettingsPresets -> Bool
(AutoDownloadSettingsPresets
 -> AutoDownloadSettingsPresets -> Bool)
-> (AutoDownloadSettingsPresets
    -> AutoDownloadSettingsPresets -> Bool)
-> Eq AutoDownloadSettingsPresets
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AutoDownloadSettingsPresets -> AutoDownloadSettingsPresets -> Bool
== :: AutoDownloadSettingsPresets -> AutoDownloadSettingsPresets -> Bool
$c/= :: AutoDownloadSettingsPresets -> AutoDownloadSettingsPresets -> Bool
/= :: AutoDownloadSettingsPresets -> AutoDownloadSettingsPresets -> Bool
Eq, Int -> AutoDownloadSettingsPresets -> ShowS
[AutoDownloadSettingsPresets] -> ShowS
AutoDownloadSettingsPresets -> String
(Int -> AutoDownloadSettingsPresets -> ShowS)
-> (AutoDownloadSettingsPresets -> String)
-> ([AutoDownloadSettingsPresets] -> ShowS)
-> Show AutoDownloadSettingsPresets
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AutoDownloadSettingsPresets -> ShowS
showsPrec :: Int -> AutoDownloadSettingsPresets -> ShowS
$cshow :: AutoDownloadSettingsPresets -> String
show :: AutoDownloadSettingsPresets -> String
$cshowList :: [AutoDownloadSettingsPresets] -> ShowS
showList :: [AutoDownloadSettingsPresets] -> ShowS
Show)

instance I.ShortShow AutoDownloadSettingsPresets where
  shortShow :: AutoDownloadSettingsPresets -> String
shortShow AutoDownloadSettingsPresets
    { low :: AutoDownloadSettingsPresets -> Maybe AutoDownloadSettings
low    = Maybe AutoDownloadSettings
low_
    , medium :: AutoDownloadSettingsPresets -> Maybe AutoDownloadSettings
medium = Maybe AutoDownloadSettings
medium_
    , high :: AutoDownloadSettingsPresets -> Maybe AutoDownloadSettings
high   = Maybe AutoDownloadSettings
high_
    }
      = String
"AutoDownloadSettingsPresets"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"low"    String -> Maybe AutoDownloadSettings -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe AutoDownloadSettings
low_
        , String
"medium" String -> Maybe AutoDownloadSettings -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe AutoDownloadSettings
medium_
        , String
"high"   String -> Maybe AutoDownloadSettings -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe AutoDownloadSettings
high_
        ]

instance AT.FromJSON AutoDownloadSettingsPresets where
  parseJSON :: Value -> Parser AutoDownloadSettingsPresets
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
"autoDownloadSettingsPresets" -> Value -> Parser AutoDownloadSettingsPresets
parseAutoDownloadSettingsPresets Value
v
      String
_                             -> Parser AutoDownloadSettingsPresets
forall a. Monoid a => a
mempty
    
    where
      parseAutoDownloadSettingsPresets :: A.Value -> AT.Parser AutoDownloadSettingsPresets
      parseAutoDownloadSettingsPresets :: Value -> Parser AutoDownloadSettingsPresets
parseAutoDownloadSettingsPresets = String
-> (Object -> Parser AutoDownloadSettingsPresets)
-> Value
-> Parser AutoDownloadSettingsPresets
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AutoDownloadSettingsPresets" ((Object -> Parser AutoDownloadSettingsPresets)
 -> Value -> Parser AutoDownloadSettingsPresets)
-> (Object -> Parser AutoDownloadSettingsPresets)
-> Value
-> Parser AutoDownloadSettingsPresets
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe AutoDownloadSettings
low_    <- Object
o Object -> Key -> Parser (Maybe AutoDownloadSettings)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"low"
        Maybe AutoDownloadSettings
medium_ <- Object
o Object -> Key -> Parser (Maybe AutoDownloadSettings)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"medium"
        Maybe AutoDownloadSettings
high_   <- Object
o Object -> Key -> Parser (Maybe AutoDownloadSettings)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"high"
        AutoDownloadSettingsPresets -> Parser AutoDownloadSettingsPresets
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AutoDownloadSettingsPresets -> Parser AutoDownloadSettingsPresets)
-> AutoDownloadSettingsPresets
-> Parser AutoDownloadSettingsPresets
forall a b. (a -> b) -> a -> b
$ AutoDownloadSettingsPresets
          { low :: Maybe AutoDownloadSettings
low    = Maybe AutoDownloadSettings
low_
          , medium :: Maybe AutoDownloadSettings
medium = Maybe AutoDownloadSettings
medium_
          , high :: Maybe AutoDownloadSettings
high   = Maybe AutoDownloadSettings
high_
          }
  parseJSON Value
_ = Parser AutoDownloadSettingsPresets
forall a. Monoid a => a
mempty