module TD.Data.ScopeAutosaveSettings
  ( ScopeAutosaveSettings(..)    
  , defaultScopeAutosaveSettings 
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

data ScopeAutosaveSettings
  = ScopeAutosaveSettings -- ^ Contains autosave settings for an autosave settings scope
    { ScopeAutosaveSettings -> Maybe Bool
autosave_photos     :: Maybe Bool -- ^ True, if photo autosave is enabled
    , ScopeAutosaveSettings -> Maybe Bool
autosave_videos     :: Maybe Bool -- ^ True, if video autosave is enabled
    , ScopeAutosaveSettings -> Maybe Int
max_video_file_size :: Maybe Int  -- ^ The maximum size of a video file to be autosaved, in bytes; 512 KB - 4000 MB
    }
  deriving (ScopeAutosaveSettings -> ScopeAutosaveSettings -> Bool
(ScopeAutosaveSettings -> ScopeAutosaveSettings -> Bool)
-> (ScopeAutosaveSettings -> ScopeAutosaveSettings -> Bool)
-> Eq ScopeAutosaveSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ScopeAutosaveSettings -> ScopeAutosaveSettings -> Bool
== :: ScopeAutosaveSettings -> ScopeAutosaveSettings -> Bool
$c/= :: ScopeAutosaveSettings -> ScopeAutosaveSettings -> Bool
/= :: ScopeAutosaveSettings -> ScopeAutosaveSettings -> Bool
Eq, Int -> ScopeAutosaveSettings -> ShowS
[ScopeAutosaveSettings] -> ShowS
ScopeAutosaveSettings -> String
(Int -> ScopeAutosaveSettings -> ShowS)
-> (ScopeAutosaveSettings -> String)
-> ([ScopeAutosaveSettings] -> ShowS)
-> Show ScopeAutosaveSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ScopeAutosaveSettings -> ShowS
showsPrec :: Int -> ScopeAutosaveSettings -> ShowS
$cshow :: ScopeAutosaveSettings -> String
show :: ScopeAutosaveSettings -> String
$cshowList :: [ScopeAutosaveSettings] -> ShowS
showList :: [ScopeAutosaveSettings] -> ShowS
Show)

instance I.ShortShow ScopeAutosaveSettings where
  shortShow :: ScopeAutosaveSettings -> String
shortShow ScopeAutosaveSettings
    { autosave_photos :: ScopeAutosaveSettings -> Maybe Bool
autosave_photos     = Maybe Bool
autosave_photos_
    , autosave_videos :: ScopeAutosaveSettings -> Maybe Bool
autosave_videos     = Maybe Bool
autosave_videos_
    , max_video_file_size :: ScopeAutosaveSettings -> Maybe Int
max_video_file_size = Maybe Int
max_video_file_size_
    }
      = String
"ScopeAutosaveSettings"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"autosave_photos"     String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
autosave_photos_
        , String
"autosave_videos"     String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
autosave_videos_
        , String
"max_video_file_size" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
max_video_file_size_
        ]

instance AT.FromJSON ScopeAutosaveSettings where
  parseJSON :: Value -> Parser ScopeAutosaveSettings
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
"scopeAutosaveSettings" -> Value -> Parser ScopeAutosaveSettings
parseScopeAutosaveSettings Value
v
      String
_                       -> Parser ScopeAutosaveSettings
forall a. Monoid a => a
mempty
    
    where
      parseScopeAutosaveSettings :: A.Value -> AT.Parser ScopeAutosaveSettings
      parseScopeAutosaveSettings :: Value -> Parser ScopeAutosaveSettings
parseScopeAutosaveSettings = String
-> (Object -> Parser ScopeAutosaveSettings)
-> Value
-> Parser ScopeAutosaveSettings
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ScopeAutosaveSettings" ((Object -> Parser ScopeAutosaveSettings)
 -> Value -> Parser ScopeAutosaveSettings)
-> (Object -> Parser ScopeAutosaveSettings)
-> Value
-> Parser ScopeAutosaveSettings
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Bool
autosave_photos_     <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"autosave_photos"
        Maybe Bool
autosave_videos_     <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"autosave_videos"
        Maybe Int
max_video_file_size_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"max_video_file_size"
        ScopeAutosaveSettings -> Parser ScopeAutosaveSettings
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ScopeAutosaveSettings -> Parser ScopeAutosaveSettings)
-> ScopeAutosaveSettings -> Parser ScopeAutosaveSettings
forall a b. (a -> b) -> a -> b
$ ScopeAutosaveSettings
          { autosave_photos :: Maybe Bool
autosave_photos     = Maybe Bool
autosave_photos_
          , autosave_videos :: Maybe Bool
autosave_videos     = Maybe Bool
autosave_videos_
          , max_video_file_size :: Maybe Int
max_video_file_size = Maybe Int
max_video_file_size_
          }
  parseJSON Value
_ = Parser ScopeAutosaveSettings
forall a. Monoid a => a
mempty

instance AT.ToJSON ScopeAutosaveSettings where
  toJSON :: ScopeAutosaveSettings -> Value
toJSON ScopeAutosaveSettings
    { autosave_photos :: ScopeAutosaveSettings -> Maybe Bool
autosave_photos     = Maybe Bool
autosave_photos_
    , autosave_videos :: ScopeAutosaveSettings -> Maybe Bool
autosave_videos     = Maybe Bool
autosave_videos_
    , max_video_file_size :: ScopeAutosaveSettings -> Maybe Int
max_video_file_size = Maybe Int
max_video_file_size_
    }
      = [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
"scopeAutosaveSettings"
        , Key
"autosave_photos"     Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
autosave_photos_
        , Key
"autosave_videos"     Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
autosave_videos_
        , Key
"max_video_file_size" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
max_video_file_size_
        ]

defaultScopeAutosaveSettings :: ScopeAutosaveSettings
defaultScopeAutosaveSettings :: ScopeAutosaveSettings
defaultScopeAutosaveSettings =
  ScopeAutosaveSettings
    { autosave_photos :: Maybe Bool
autosave_photos     = Maybe Bool
forall a. Maybe a
Nothing
    , autosave_videos :: Maybe Bool
autosave_videos     = Maybe Bool
forall a. Maybe a
Nothing
    , max_video_file_size :: Maybe Int
max_video_file_size = Maybe Int
forall a. Maybe a
Nothing
    }