module TD.Data.StorageStatisticsByFileType
  (StorageStatisticsByFileType(..)) 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.FileType as FileType

data StorageStatisticsByFileType
  = StorageStatisticsByFileType -- ^ Contains the storage usage statistics for a specific file type
    { StorageStatisticsByFileType -> Maybe FileType
file_type :: Maybe FileType.FileType -- ^ File type
    , StorageStatisticsByFileType -> Maybe Int
size      :: Maybe Int               -- ^ Total size of the files, in bytes
    , StorageStatisticsByFileType -> Maybe Int
count     :: Maybe Int               -- ^ Total number of files
    }
  deriving (StorageStatisticsByFileType -> StorageStatisticsByFileType -> Bool
(StorageStatisticsByFileType
 -> StorageStatisticsByFileType -> Bool)
-> (StorageStatisticsByFileType
    -> StorageStatisticsByFileType -> Bool)
-> Eq StorageStatisticsByFileType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StorageStatisticsByFileType -> StorageStatisticsByFileType -> Bool
== :: StorageStatisticsByFileType -> StorageStatisticsByFileType -> Bool
$c/= :: StorageStatisticsByFileType -> StorageStatisticsByFileType -> Bool
/= :: StorageStatisticsByFileType -> StorageStatisticsByFileType -> Bool
Eq, Int -> StorageStatisticsByFileType -> ShowS
[StorageStatisticsByFileType] -> ShowS
StorageStatisticsByFileType -> String
(Int -> StorageStatisticsByFileType -> ShowS)
-> (StorageStatisticsByFileType -> String)
-> ([StorageStatisticsByFileType] -> ShowS)
-> Show StorageStatisticsByFileType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StorageStatisticsByFileType -> ShowS
showsPrec :: Int -> StorageStatisticsByFileType -> ShowS
$cshow :: StorageStatisticsByFileType -> String
show :: StorageStatisticsByFileType -> String
$cshowList :: [StorageStatisticsByFileType] -> ShowS
showList :: [StorageStatisticsByFileType] -> ShowS
Show)

instance I.ShortShow StorageStatisticsByFileType where
  shortShow :: StorageStatisticsByFileType -> String
shortShow StorageStatisticsByFileType
    { file_type :: StorageStatisticsByFileType -> Maybe FileType
file_type = Maybe FileType
file_type_
    , size :: StorageStatisticsByFileType -> Maybe Int
size      = Maybe Int
size_
    , count :: StorageStatisticsByFileType -> Maybe Int
count     = Maybe Int
count_
    }
      = String
"StorageStatisticsByFileType"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"file_type" String -> Maybe FileType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FileType
file_type_
        , String
"size"      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
size_
        , String
"count"     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
count_
        ]

instance AT.FromJSON StorageStatisticsByFileType where
  parseJSON :: Value -> Parser StorageStatisticsByFileType
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
"storageStatisticsByFileType" -> Value -> Parser StorageStatisticsByFileType
parseStorageStatisticsByFileType Value
v
      String
_                             -> Parser StorageStatisticsByFileType
forall a. Monoid a => a
mempty
    
    where
      parseStorageStatisticsByFileType :: A.Value -> AT.Parser StorageStatisticsByFileType
      parseStorageStatisticsByFileType :: Value -> Parser StorageStatisticsByFileType
parseStorageStatisticsByFileType = String
-> (Object -> Parser StorageStatisticsByFileType)
-> Value
-> Parser StorageStatisticsByFileType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StorageStatisticsByFileType" ((Object -> Parser StorageStatisticsByFileType)
 -> Value -> Parser StorageStatisticsByFileType)
-> (Object -> Parser StorageStatisticsByFileType)
-> Value
-> Parser StorageStatisticsByFileType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe FileType
file_type_ <- Object
o Object -> Key -> Parser (Maybe FileType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"file_type"
        Maybe Int
size_      <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"size"
        Maybe Int
count_     <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"count"
        StorageStatisticsByFileType -> Parser StorageStatisticsByFileType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StorageStatisticsByFileType -> Parser StorageStatisticsByFileType)
-> StorageStatisticsByFileType
-> Parser StorageStatisticsByFileType
forall a b. (a -> b) -> a -> b
$ StorageStatisticsByFileType
          { file_type :: Maybe FileType
file_type = Maybe FileType
file_type_
          , size :: Maybe Int
size      = Maybe Int
size_
          , count :: Maybe Int
count     = Maybe Int
count_
          }
  parseJSON Value
_ = Parser StorageStatisticsByFileType
forall a. Monoid a => a
mempty