module TD.Query.OptimizeStorage
  (OptimizeStorage(..)
  , defaultOptimizeStorage
  ) 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

-- | Optimizes storage usage, i.e. deletes some files and returns new storage usage statistics. Secret thumbnails can't be deleted. Returns 'TD.Data.StorageStatistics.StorageStatistics'
data OptimizeStorage
  = OptimizeStorage
    { OptimizeStorage -> Maybe Int
size                           :: Maybe Int                 -- ^ Limit on the total size of files after deletion, in bytes. Pass -1 to use the default limit
    , OptimizeStorage -> Maybe Int
ttl                            :: Maybe Int                 -- ^ Limit on the time that has passed since the last time a file was accessed (or creation time for some filesystems). Pass -1 to use the default limit
    , OptimizeStorage -> Maybe Int
count                          :: Maybe Int                 -- ^ Limit on the total number of files after deletion. Pass -1 to use the default limit
    , OptimizeStorage -> Maybe Int
immunity_delay                 :: Maybe Int                 -- ^ The amount of time after the creation of a file during which it can't be deleted, in seconds. Pass -1 to use the default value
    , OptimizeStorage -> Maybe [FileType]
file_types                     :: Maybe [FileType.FileType] -- ^ If non-empty, only files with the given types are considered. By default, all types except thumbnails, profile photos, stickers and wallpapers are deleted
    , OptimizeStorage -> Maybe [Int]
chat_ids                       :: Maybe [Int]               -- ^ If non-empty, only files from the given chats are considered. Use 0 as chat identifier to delete files not belonging to any chat (e.g., profile photos)
    , OptimizeStorage -> Maybe [Int]
exclude_chat_ids               :: Maybe [Int]               -- ^ If non-empty, files from the given chats are excluded. Use 0 as chat identifier to exclude all files not belonging to any chat (e.g., profile photos)
    , OptimizeStorage -> Maybe Bool
return_deleted_file_statistics :: Maybe Bool                -- ^ Pass true if statistics about the files that were deleted must be returned instead of the whole storage usage statistics. Affects only returned statistics
    , OptimizeStorage -> Maybe Int
chat_limit                     :: Maybe Int                 -- ^ Same as in getStorageStatistics. Affects only returned statistics
    }
  deriving (OptimizeStorage -> OptimizeStorage -> Bool
(OptimizeStorage -> OptimizeStorage -> Bool)
-> (OptimizeStorage -> OptimizeStorage -> Bool)
-> Eq OptimizeStorage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OptimizeStorage -> OptimizeStorage -> Bool
== :: OptimizeStorage -> OptimizeStorage -> Bool
$c/= :: OptimizeStorage -> OptimizeStorage -> Bool
/= :: OptimizeStorage -> OptimizeStorage -> Bool
Eq, Int -> OptimizeStorage -> ShowS
[OptimizeStorage] -> ShowS
OptimizeStorage -> String
(Int -> OptimizeStorage -> ShowS)
-> (OptimizeStorage -> String)
-> ([OptimizeStorage] -> ShowS)
-> Show OptimizeStorage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OptimizeStorage -> ShowS
showsPrec :: Int -> OptimizeStorage -> ShowS
$cshow :: OptimizeStorage -> String
show :: OptimizeStorage -> String
$cshowList :: [OptimizeStorage] -> ShowS
showList :: [OptimizeStorage] -> ShowS
Show)

instance I.ShortShow OptimizeStorage where
  shortShow :: OptimizeStorage -> String
shortShow
    OptimizeStorage
      { size :: OptimizeStorage -> Maybe Int
size                           = Maybe Int
size_
      , ttl :: OptimizeStorage -> Maybe Int
ttl                            = Maybe Int
ttl_
      , count :: OptimizeStorage -> Maybe Int
count                          = Maybe Int
count_
      , immunity_delay :: OptimizeStorage -> Maybe Int
immunity_delay                 = Maybe Int
immunity_delay_
      , file_types :: OptimizeStorage -> Maybe [FileType]
file_types                     = Maybe [FileType]
file_types_
      , chat_ids :: OptimizeStorage -> Maybe [Int]
chat_ids                       = Maybe [Int]
chat_ids_
      , exclude_chat_ids :: OptimizeStorage -> Maybe [Int]
exclude_chat_ids               = Maybe [Int]
exclude_chat_ids_
      , return_deleted_file_statistics :: OptimizeStorage -> Maybe Bool
return_deleted_file_statistics = Maybe Bool
return_deleted_file_statistics_
      , chat_limit :: OptimizeStorage -> Maybe Int
chat_limit                     = Maybe Int
chat_limit_
      }
        = String
"OptimizeStorage"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"size"                           String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
size_
          , String
"ttl"                            String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
ttl_
          , String
"count"                          String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
count_
          , String
"immunity_delay"                 String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
immunity_delay_
          , String
"file_types"                     String -> Maybe [FileType] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [FileType]
file_types_
          , String
"chat_ids"                       String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
chat_ids_
          , String
"exclude_chat_ids"               String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
exclude_chat_ids_
          , String
"return_deleted_file_statistics" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
return_deleted_file_statistics_
          , String
"chat_limit"                     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_limit_
          ]

instance AT.ToJSON OptimizeStorage where
  toJSON :: OptimizeStorage -> Value
toJSON
    OptimizeStorage
      { size :: OptimizeStorage -> Maybe Int
size                           = Maybe Int
size_
      , ttl :: OptimizeStorage -> Maybe Int
ttl                            = Maybe Int
ttl_
      , count :: OptimizeStorage -> Maybe Int
count                          = Maybe Int
count_
      , immunity_delay :: OptimizeStorage -> Maybe Int
immunity_delay                 = Maybe Int
immunity_delay_
      , file_types :: OptimizeStorage -> Maybe [FileType]
file_types                     = Maybe [FileType]
file_types_
      , chat_ids :: OptimizeStorage -> Maybe [Int]
chat_ids                       = Maybe [Int]
chat_ids_
      , exclude_chat_ids :: OptimizeStorage -> Maybe [Int]
exclude_chat_ids               = Maybe [Int]
exclude_chat_ids_
      , return_deleted_file_statistics :: OptimizeStorage -> Maybe Bool
return_deleted_file_statistics = Maybe Bool
return_deleted_file_statistics_
      , chat_limit :: OptimizeStorage -> Maybe Int
chat_limit                     = Maybe Int
chat_limit_
      }
        = [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
"optimizeStorage"
          , Key
"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
size_
          , Key
"ttl"                            Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
ttl_
          , Key
"count"                          Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
count_
          , Key
"immunity_delay"                 Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
immunity_delay_
          , Key
"file_types"                     Key -> Maybe [FileType] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [FileType]
file_types_
          , Key
"chat_ids"                       Key -> Maybe [Int] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [Int]
chat_ids_
          , Key
"exclude_chat_ids"               Key -> Maybe [Int] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [Int]
exclude_chat_ids_
          , Key
"return_deleted_file_statistics" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
return_deleted_file_statistics_
          , Key
"chat_limit"                     Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
chat_limit_
          ]

defaultOptimizeStorage :: OptimizeStorage
defaultOptimizeStorage :: OptimizeStorage
defaultOptimizeStorage =
  OptimizeStorage
    { size :: Maybe Int
size                           = Maybe Int
forall a. Maybe a
Nothing
    , ttl :: Maybe Int
ttl                            = Maybe Int
forall a. Maybe a
Nothing
    , count :: Maybe Int
count                          = Maybe Int
forall a. Maybe a
Nothing
    , immunity_delay :: Maybe Int
immunity_delay                 = Maybe Int
forall a. Maybe a
Nothing
    , file_types :: Maybe [FileType]
file_types                     = Maybe [FileType]
forall a. Maybe a
Nothing
    , chat_ids :: Maybe [Int]
chat_ids                       = Maybe [Int]
forall a. Maybe a
Nothing
    , exclude_chat_ids :: Maybe [Int]
exclude_chat_ids               = Maybe [Int]
forall a. Maybe a
Nothing
    , return_deleted_file_statistics :: Maybe Bool
return_deleted_file_statistics = Maybe Bool
forall a. Maybe a
Nothing
    , chat_limit :: Maybe Int
chat_limit                     = Maybe Int
forall a. Maybe a
Nothing
    }