{-# LANGUAGE TemplateHaskell #-}

-- | Audit Log models
module Calamity.Types.Model.Guild.AuditLog (
  AuditLog (..),
  AuditLogEntry (..),
  AuditLogEntryInfo (..),
  AuditLogChange (..),
  AuditLogAction (..),
) where

import Calamity.Internal.SnowflakeMap (SnowflakeMap)
import Calamity.Types.Model.Channel
import Calamity.Types.Model.User
import Calamity.Types.Snowflake
import Data.Aeson ((.:), (.:?))
import qualified Data.Aeson as Aeson
import Data.Scientific
import Data.Text (Text)
import Optics.TH
import qualified TextShow
import TextShow.TH

data AuditLog = AuditLog
  { AuditLog -> SnowflakeMap Webhook
webhooks :: SnowflakeMap Webhook
  , AuditLog -> SnowflakeMap User
users :: SnowflakeMap User
  , AuditLog -> SnowflakeMap AuditLogEntry
auditLogEntries :: SnowflakeMap AuditLogEntry
  }
  deriving (Int -> AuditLog -> ShowS
[AuditLog] -> ShowS
AuditLog -> String
(Int -> AuditLog -> ShowS)
-> (AuditLog -> String) -> ([AuditLog] -> ShowS) -> Show AuditLog
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuditLog] -> ShowS
$cshowList :: [AuditLog] -> ShowS
show :: AuditLog -> String
$cshow :: AuditLog -> String
showsPrec :: Int -> AuditLog -> ShowS
$cshowsPrec :: Int -> AuditLog -> ShowS
Show)

data AuditLogEntry = AuditLogEntry
  { AuditLogEntry -> Maybe (Snowflake ())
targetID :: Maybe (Snowflake ())
  , AuditLogEntry -> [AuditLogChange]
changes :: [AuditLogChange]
  , AuditLogEntry -> Snowflake User
userID :: Snowflake User
  , AuditLogEntry -> Snowflake AuditLogEntry
id :: Snowflake AuditLogEntry
  , AuditLogEntry -> AuditLogAction
actionType :: AuditLogAction
  , AuditLogEntry -> Maybe AuditLogEntryInfo
options :: Maybe AuditLogEntryInfo
  , AuditLogEntry -> Maybe Text
reason :: Maybe Text
  }
  deriving (Int -> AuditLogEntry -> ShowS
[AuditLogEntry] -> ShowS
AuditLogEntry -> String
(Int -> AuditLogEntry -> ShowS)
-> (AuditLogEntry -> String)
-> ([AuditLogEntry] -> ShowS)
-> Show AuditLogEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuditLogEntry] -> ShowS
$cshowList :: [AuditLogEntry] -> ShowS
show :: AuditLogEntry -> String
$cshow :: AuditLogEntry -> String
showsPrec :: Int -> AuditLogEntry -> ShowS
$cshowsPrec :: Int -> AuditLogEntry -> ShowS
Show)
  deriving (HasID User) via HasIDField "userID" AuditLogEntry
  deriving (HasID AuditLogEntry) via HasIDField "id" AuditLogEntry

instance Aeson.FromJSON AuditLogEntry where
  parseJSON :: Value -> Parser AuditLogEntry
parseJSON = String
-> (Object -> Parser AuditLogEntry)
-> Value
-> Parser AuditLogEntry
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"AuditLogEntry" ((Object -> Parser AuditLogEntry) -> Value -> Parser AuditLogEntry)
-> (Object -> Parser AuditLogEntry)
-> Value
-> Parser AuditLogEntry
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Maybe (Snowflake ())
-> [AuditLogChange]
-> Snowflake User
-> Snowflake AuditLogEntry
-> AuditLogAction
-> Maybe AuditLogEntryInfo
-> Maybe Text
-> AuditLogEntry
AuditLogEntry
      (Maybe (Snowflake ())
 -> [AuditLogChange]
 -> Snowflake User
 -> Snowflake AuditLogEntry
 -> AuditLogAction
 -> Maybe AuditLogEntryInfo
 -> Maybe Text
 -> AuditLogEntry)
-> Parser (Maybe (Snowflake ()))
-> Parser
     ([AuditLogChange]
      -> Snowflake User
      -> Snowflake AuditLogEntry
      -> AuditLogAction
      -> Maybe AuditLogEntryInfo
      -> Maybe Text
      -> AuditLogEntry)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe (Snowflake ()))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"target_id"
      Parser
  ([AuditLogChange]
   -> Snowflake User
   -> Snowflake AuditLogEntry
   -> AuditLogAction
   -> Maybe AuditLogEntryInfo
   -> Maybe Text
   -> AuditLogEntry)
-> Parser [AuditLogChange]
-> Parser
     (Snowflake User
      -> Snowflake AuditLogEntry
      -> AuditLogAction
      -> Maybe AuditLogEntryInfo
      -> Maybe Text
      -> AuditLogEntry)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser [AuditLogChange]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"changes"
      Parser
  (Snowflake User
   -> Snowflake AuditLogEntry
   -> AuditLogAction
   -> Maybe AuditLogEntryInfo
   -> Maybe Text
   -> AuditLogEntry)
-> Parser (Snowflake User)
-> Parser
     (Snowflake AuditLogEntry
      -> AuditLogAction
      -> Maybe AuditLogEntryInfo
      -> Maybe Text
      -> AuditLogEntry)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Snowflake User)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"user_id"
      Parser
  (Snowflake AuditLogEntry
   -> AuditLogAction
   -> Maybe AuditLogEntryInfo
   -> Maybe Text
   -> AuditLogEntry)
-> Parser (Snowflake AuditLogEntry)
-> Parser
     (AuditLogAction
      -> Maybe AuditLogEntryInfo -> Maybe Text -> AuditLogEntry)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Snowflake AuditLogEntry)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
      Parser
  (AuditLogAction
   -> Maybe AuditLogEntryInfo -> Maybe Text -> AuditLogEntry)
-> Parser AuditLogAction
-> Parser (Maybe AuditLogEntryInfo -> Maybe Text -> AuditLogEntry)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser AuditLogAction
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"action_type"
      Parser (Maybe AuditLogEntryInfo -> Maybe Text -> AuditLogEntry)
-> Parser (Maybe AuditLogEntryInfo)
-> Parser (Maybe Text -> AuditLogEntry)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe AuditLogEntryInfo)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"options"
      Parser (Maybe Text -> AuditLogEntry)
-> Parser (Maybe Text) -> Parser AuditLogEntry
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"reason"

data AuditLogEntryInfo = AuditLogEntryInfo
  { AuditLogEntryInfo -> Maybe Text
deleteMemberDays :: Maybe Text
  , AuditLogEntryInfo -> Maybe Text
membersRemoved :: Maybe Text
  , AuditLogEntryInfo -> Maybe (Snowflake Channel)
channelID :: Maybe (Snowflake Channel)
  , AuditLogEntryInfo -> Maybe (Snowflake Message)
messageID :: Maybe (Snowflake Message)
  , AuditLogEntryInfo -> Maybe Text
count :: Maybe Text
  , AuditLogEntryInfo -> Maybe (Snowflake ())
id :: Maybe (Snowflake ())
  , AuditLogEntryInfo -> Maybe Text
type_ :: Maybe Text
  , AuditLogEntryInfo -> Maybe Text
roleName :: Maybe Text
  }
  deriving (Int -> AuditLogEntryInfo -> ShowS
[AuditLogEntryInfo] -> ShowS
AuditLogEntryInfo -> String
(Int -> AuditLogEntryInfo -> ShowS)
-> (AuditLogEntryInfo -> String)
-> ([AuditLogEntryInfo] -> ShowS)
-> Show AuditLogEntryInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuditLogEntryInfo] -> ShowS
$cshowList :: [AuditLogEntryInfo] -> ShowS
show :: AuditLogEntryInfo -> String
$cshow :: AuditLogEntryInfo -> String
showsPrec :: Int -> AuditLogEntryInfo -> ShowS
$cshowsPrec :: Int -> AuditLogEntryInfo -> ShowS
Show)

instance Aeson.FromJSON AuditLogEntryInfo where
  parseJSON :: Value -> Parser AuditLogEntryInfo
parseJSON = String
-> (Object -> Parser AuditLogEntryInfo)
-> Value
-> Parser AuditLogEntryInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"AudotLogEntryInfo" ((Object -> Parser AuditLogEntryInfo)
 -> Value -> Parser AuditLogEntryInfo)
-> (Object -> Parser AuditLogEntryInfo)
-> Value
-> Parser AuditLogEntryInfo
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Maybe Text
-> Maybe Text
-> Maybe (Snowflake Channel)
-> Maybe (Snowflake Message)
-> Maybe Text
-> Maybe (Snowflake ())
-> Maybe Text
-> Maybe Text
-> AuditLogEntryInfo
AuditLogEntryInfo
      (Maybe Text
 -> Maybe Text
 -> Maybe (Snowflake Channel)
 -> Maybe (Snowflake Message)
 -> Maybe Text
 -> Maybe (Snowflake ())
 -> Maybe Text
 -> Maybe Text
 -> AuditLogEntryInfo)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe (Snowflake Channel)
      -> Maybe (Snowflake Message)
      -> Maybe Text
      -> Maybe (Snowflake ())
      -> Maybe Text
      -> Maybe Text
      -> AuditLogEntryInfo)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"delete_member_days"
      Parser
  (Maybe Text
   -> Maybe (Snowflake Channel)
   -> Maybe (Snowflake Message)
   -> Maybe Text
   -> Maybe (Snowflake ())
   -> Maybe Text
   -> Maybe Text
   -> AuditLogEntryInfo)
-> Parser (Maybe Text)
-> Parser
     (Maybe (Snowflake Channel)
      -> Maybe (Snowflake Message)
      -> Maybe Text
      -> Maybe (Snowflake ())
      -> Maybe Text
      -> Maybe Text
      -> AuditLogEntryInfo)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"members_removed"
      Parser
  (Maybe (Snowflake Channel)
   -> Maybe (Snowflake Message)
   -> Maybe Text
   -> Maybe (Snowflake ())
   -> Maybe Text
   -> Maybe Text
   -> AuditLogEntryInfo)
-> Parser (Maybe (Snowflake Channel))
-> Parser
     (Maybe (Snowflake Message)
      -> Maybe Text
      -> Maybe (Snowflake ())
      -> Maybe Text
      -> Maybe Text
      -> AuditLogEntryInfo)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe (Snowflake Channel))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"channel_id"
      Parser
  (Maybe (Snowflake Message)
   -> Maybe Text
   -> Maybe (Snowflake ())
   -> Maybe Text
   -> Maybe Text
   -> AuditLogEntryInfo)
-> Parser (Maybe (Snowflake Message))
-> Parser
     (Maybe Text
      -> Maybe (Snowflake ())
      -> Maybe Text
      -> Maybe Text
      -> AuditLogEntryInfo)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe (Snowflake Message))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"message_id"
      Parser
  (Maybe Text
   -> Maybe (Snowflake ())
   -> Maybe Text
   -> Maybe Text
   -> AuditLogEntryInfo)
-> Parser (Maybe Text)
-> Parser
     (Maybe (Snowflake ())
      -> Maybe Text -> Maybe Text -> AuditLogEntryInfo)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"count"
      Parser
  (Maybe (Snowflake ())
   -> Maybe Text -> Maybe Text -> AuditLogEntryInfo)
-> Parser (Maybe (Snowflake ()))
-> Parser (Maybe Text -> Maybe Text -> AuditLogEntryInfo)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe (Snowflake ()))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"id"
      Parser (Maybe Text -> Maybe Text -> AuditLogEntryInfo)
-> Parser (Maybe Text) -> Parser (Maybe Text -> AuditLogEntryInfo)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"type"
      Parser (Maybe Text -> AuditLogEntryInfo)
-> Parser (Maybe Text) -> Parser AuditLogEntryInfo
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"role_name"

data AuditLogChange = AuditLogChange
  { AuditLogChange -> Maybe Value
newValue :: Maybe Aeson.Value
  , AuditLogChange -> Maybe Value
oldValue :: Maybe Aeson.Value
  , AuditLogChange -> Text
key :: Text
  }
  deriving (Int -> AuditLogChange -> ShowS
[AuditLogChange] -> ShowS
AuditLogChange -> String
(Int -> AuditLogChange -> ShowS)
-> (AuditLogChange -> String)
-> ([AuditLogChange] -> ShowS)
-> Show AuditLogChange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuditLogChange] -> ShowS
$cshowList :: [AuditLogChange] -> ShowS
show :: AuditLogChange -> String
$cshow :: AuditLogChange -> String
showsPrec :: Int -> AuditLogChange -> ShowS
$cshowsPrec :: Int -> AuditLogChange -> ShowS
Show)
  deriving (Int -> AuditLogChange -> Builder
Int -> AuditLogChange -> Text
Int -> AuditLogChange -> Text
[AuditLogChange] -> Builder
[AuditLogChange] -> Text
[AuditLogChange] -> Text
AuditLogChange -> Builder
AuditLogChange -> Text
AuditLogChange -> Text
(Int -> AuditLogChange -> Builder)
-> (AuditLogChange -> Builder)
-> ([AuditLogChange] -> Builder)
-> (Int -> AuditLogChange -> Text)
-> (AuditLogChange -> Text)
-> ([AuditLogChange] -> Text)
-> (Int -> AuditLogChange -> Text)
-> (AuditLogChange -> Text)
-> ([AuditLogChange] -> Text)
-> TextShow AuditLogChange
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
showtlList :: [AuditLogChange] -> Text
$cshowtlList :: [AuditLogChange] -> Text
showtl :: AuditLogChange -> Text
$cshowtl :: AuditLogChange -> Text
showtlPrec :: Int -> AuditLogChange -> Text
$cshowtlPrec :: Int -> AuditLogChange -> Text
showtList :: [AuditLogChange] -> Text
$cshowtList :: [AuditLogChange] -> Text
showt :: AuditLogChange -> Text
$cshowt :: AuditLogChange -> Text
showtPrec :: Int -> AuditLogChange -> Text
$cshowtPrec :: Int -> AuditLogChange -> Text
showbList :: [AuditLogChange] -> Builder
$cshowbList :: [AuditLogChange] -> Builder
showb :: AuditLogChange -> Builder
$cshowb :: AuditLogChange -> Builder
showbPrec :: Int -> AuditLogChange -> Builder
$cshowbPrec :: Int -> AuditLogChange -> Builder
TextShow.TextShow) via TextShow.FromStringShow AuditLogChange

instance Aeson.FromJSON AuditLogChange where
  parseJSON :: Value -> Parser AuditLogChange
parseJSON = String
-> (Object -> Parser AuditLogChange)
-> Value
-> Parser AuditLogChange
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"AudotLogChange" ((Object -> Parser AuditLogChange)
 -> Value -> Parser AuditLogChange)
-> (Object -> Parser AuditLogChange)
-> Value
-> Parser AuditLogChange
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Maybe Value -> Maybe Value -> Text -> AuditLogChange
AuditLogChange
      (Maybe Value -> Maybe Value -> Text -> AuditLogChange)
-> Parser (Maybe Value)
-> Parser (Maybe Value -> Text -> AuditLogChange)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"new_value"
      Parser (Maybe Value -> Text -> AuditLogChange)
-> Parser (Maybe Value) -> Parser (Text -> AuditLogChange)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"old_value"
      Parser (Text -> AuditLogChange)
-> Parser Text -> Parser AuditLogChange
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"key"

data AuditLogAction
  = GUILD_UPDATE
  | CHANNEL_CREATE
  | CHANNEL_UPDATE
  | CHANNEL_DELETE
  | CHANNEL_OVERWRITE_CREATE
  | CHANNEL_OVERWRITE_UPDATE
  | CHANNEL_OVERWRITE_DELETE
  | MEMBER_KICK
  | MEMBER_PRUNE
  | MEMBER_BAN_ADD
  | MEMBER_BAN_REMOVE
  | MEMBER_UPDATE
  | MEMBER_ROLE_UPDATE
  | MEMBER_MOVE
  | MEMBER_DISCONNECT
  | BOT_ADD
  | ROLE_CREATE
  | ROLE_UPDATE
  | ROLE_DELETE
  | INVITE_CREATE
  | INVITE_UPDATE
  | INVITE_DELETE
  | WEBHOOK_CREATE
  | WEBHOOK_UPDATE
  | WEBHOOK_DELETE
  | EMOJI_CREATE
  | EMOJI_UPDATE
  | EMOJI_DELETE
  | MESSAGE_DELETE
  | MESSAGE_BULK_DELETE
  | MESSAGE_PIN
  | MESSAGE_UNPIN
  | INTEGRATION_CREATE
  | INTEGRATION_UPDATE
  | INTEGRATION_DELETE
  deriving (Int -> AuditLogAction -> ShowS
[AuditLogAction] -> ShowS
AuditLogAction -> String
(Int -> AuditLogAction -> ShowS)
-> (AuditLogAction -> String)
-> ([AuditLogAction] -> ShowS)
-> Show AuditLogAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuditLogAction] -> ShowS
$cshowList :: [AuditLogAction] -> ShowS
show :: AuditLogAction -> String
$cshow :: AuditLogAction -> String
showsPrec :: Int -> AuditLogAction -> ShowS
$cshowsPrec :: Int -> AuditLogAction -> ShowS
Show)

instance Enum AuditLogAction where
  toEnum :: Int -> AuditLogAction
toEnum Int
v = case Int
v of
    Int
1 -> AuditLogAction
GUILD_UPDATE
    Int
10 -> AuditLogAction
CHANNEL_CREATE
    Int
11 -> AuditLogAction
CHANNEL_UPDATE
    Int
12 -> AuditLogAction
CHANNEL_DELETE
    Int
13 -> AuditLogAction
CHANNEL_OVERWRITE_CREATE
    Int
14 -> AuditLogAction
CHANNEL_OVERWRITE_UPDATE
    Int
15 -> AuditLogAction
CHANNEL_OVERWRITE_DELETE
    Int
20 -> AuditLogAction
MEMBER_KICK
    Int
21 -> AuditLogAction
MEMBER_PRUNE
    Int
22 -> AuditLogAction
MEMBER_BAN_ADD
    Int
23 -> AuditLogAction
MEMBER_BAN_REMOVE
    Int
24 -> AuditLogAction
MEMBER_UPDATE
    Int
25 -> AuditLogAction
MEMBER_ROLE_UPDATE
    Int
26 -> AuditLogAction
MEMBER_MOVE
    Int
27 -> AuditLogAction
MEMBER_DISCONNECT
    Int
28 -> AuditLogAction
BOT_ADD
    Int
30 -> AuditLogAction
ROLE_CREATE
    Int
31 -> AuditLogAction
ROLE_UPDATE
    Int
32 -> AuditLogAction
ROLE_DELETE
    Int
40 -> AuditLogAction
INVITE_CREATE
    Int
41 -> AuditLogAction
INVITE_UPDATE
    Int
42 -> AuditLogAction
INVITE_DELETE
    Int
50 -> AuditLogAction
WEBHOOK_CREATE
    Int
51 -> AuditLogAction
WEBHOOK_UPDATE
    Int
52 -> AuditLogAction
WEBHOOK_DELETE
    Int
60 -> AuditLogAction
EMOJI_CREATE
    Int
61 -> AuditLogAction
EMOJI_UPDATE
    Int
62 -> AuditLogAction
EMOJI_DELETE
    Int
72 -> AuditLogAction
MESSAGE_DELETE
    Int
73 -> AuditLogAction
MESSAGE_BULK_DELETE
    Int
74 -> AuditLogAction
MESSAGE_PIN
    Int
75 -> AuditLogAction
MESSAGE_UNPIN
    Int
80 -> AuditLogAction
INTEGRATION_CREATE
    Int
81 -> AuditLogAction
INTEGRATION_UPDATE
    Int
82 -> AuditLogAction
INTEGRATION_DELETE
    Int
_ -> String -> AuditLogAction
forall a. HasCallStack => String -> a
error (String -> AuditLogAction) -> String -> AuditLogAction
forall a b. (a -> b) -> a -> b
$ String
"Invalid AuditLogAction: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
v

  fromEnum :: AuditLogAction -> Int
fromEnum AuditLogAction
v = case AuditLogAction
v of
    AuditLogAction
GUILD_UPDATE -> Int
1
    AuditLogAction
CHANNEL_CREATE -> Int
10
    AuditLogAction
CHANNEL_UPDATE -> Int
11
    AuditLogAction
CHANNEL_DELETE -> Int
12
    AuditLogAction
CHANNEL_OVERWRITE_CREATE -> Int
13
    AuditLogAction
CHANNEL_OVERWRITE_UPDATE -> Int
14
    AuditLogAction
CHANNEL_OVERWRITE_DELETE -> Int
15
    AuditLogAction
MEMBER_KICK -> Int
20
    AuditLogAction
MEMBER_PRUNE -> Int
21
    AuditLogAction
MEMBER_BAN_ADD -> Int
22
    AuditLogAction
MEMBER_BAN_REMOVE -> Int
23
    AuditLogAction
MEMBER_UPDATE -> Int
24
    AuditLogAction
MEMBER_ROLE_UPDATE -> Int
25
    AuditLogAction
MEMBER_MOVE -> Int
26
    AuditLogAction
MEMBER_DISCONNECT -> Int
27
    AuditLogAction
BOT_ADD -> Int
28
    AuditLogAction
ROLE_CREATE -> Int
30
    AuditLogAction
ROLE_UPDATE -> Int
31
    AuditLogAction
ROLE_DELETE -> Int
32
    AuditLogAction
INVITE_CREATE -> Int
40
    AuditLogAction
INVITE_UPDATE -> Int
41
    AuditLogAction
INVITE_DELETE -> Int
42
    AuditLogAction
WEBHOOK_CREATE -> Int
50
    AuditLogAction
WEBHOOK_UPDATE -> Int
51
    AuditLogAction
WEBHOOK_DELETE -> Int
52
    AuditLogAction
EMOJI_CREATE -> Int
60
    AuditLogAction
EMOJI_UPDATE -> Int
61
    AuditLogAction
EMOJI_DELETE -> Int
62
    AuditLogAction
MESSAGE_DELETE -> Int
72
    AuditLogAction
MESSAGE_BULK_DELETE -> Int
73
    AuditLogAction
MESSAGE_PIN -> Int
74
    AuditLogAction
MESSAGE_UNPIN -> Int
75
    AuditLogAction
INTEGRATION_CREATE -> Int
80
    AuditLogAction
INTEGRATION_UPDATE -> Int
81
    AuditLogAction
INTEGRATION_DELETE -> Int
82

instance Aeson.FromJSON AuditLogAction where
  parseJSON :: Value -> Parser AuditLogAction
parseJSON = String
-> (Scientific -> Parser AuditLogAction)
-> Value
-> Parser AuditLogAction
forall a. String -> (Scientific -> Parser a) -> Value -> Parser a
Aeson.withScientific String
"AuditLogAction" ((Scientific -> Parser AuditLogAction)
 -> Value -> Parser AuditLogAction)
-> (Scientific -> Parser AuditLogAction)
-> Value
-> Parser AuditLogAction
forall a b. (a -> b) -> a -> b
$ \Scientific
n -> case forall i. (Integral i, Bounded i) => Scientific -> Maybe i
toBoundedInteger @Int Scientific
n of
    Just Int
v -> case Int
v of --  no safe toEnum :S
      Int
1 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
GUILD_UPDATE
      Int
10 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
CHANNEL_CREATE
      Int
11 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
CHANNEL_UPDATE
      Int
12 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
CHANNEL_DELETE
      Int
13 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
CHANNEL_OVERWRITE_CREATE
      Int
14 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
CHANNEL_OVERWRITE_UPDATE
      Int
15 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
CHANNEL_OVERWRITE_DELETE
      Int
20 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
MEMBER_KICK
      Int
21 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
MEMBER_PRUNE
      Int
22 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
MEMBER_BAN_ADD
      Int
23 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
MEMBER_BAN_REMOVE
      Int
24 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
MEMBER_UPDATE
      Int
25 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
MEMBER_ROLE_UPDATE
      Int
26 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
MEMBER_MOVE
      Int
27 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
MEMBER_DISCONNECT
      Int
28 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
BOT_ADD
      Int
30 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
ROLE_CREATE
      Int
31 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
ROLE_UPDATE
      Int
32 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
ROLE_DELETE
      Int
40 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
INVITE_CREATE
      Int
41 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
INVITE_UPDATE
      Int
42 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
INVITE_DELETE
      Int
50 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
WEBHOOK_CREATE
      Int
51 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
WEBHOOK_UPDATE
      Int
52 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
WEBHOOK_DELETE
      Int
60 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
EMOJI_CREATE
      Int
61 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
EMOJI_UPDATE
      Int
62 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
EMOJI_DELETE
      Int
72 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
MESSAGE_DELETE
      Int
73 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
MESSAGE_BULK_DELETE
      Int
74 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
MESSAGE_PIN
      Int
75 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
MESSAGE_UNPIN
      Int
80 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
INTEGRATION_CREATE
      Int
81 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
INTEGRATION_UPDATE
      Int
82 -> AuditLogAction -> Parser AuditLogAction
forall (f :: * -> *) a. Applicative f => a -> f a
pure AuditLogAction
INTEGRATION_DELETE
      Int
_ -> String -> Parser AuditLogAction
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser AuditLogAction)
-> String -> Parser AuditLogAction
forall a b. (a -> b) -> a -> b
$ String
"Invalid AuditLogAction: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Scientific -> String
forall a. Show a => a -> String
show Scientific
n
    Maybe Int
Nothing -> String -> Parser AuditLogAction
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser AuditLogAction)
-> String -> Parser AuditLogAction
forall a b. (a -> b) -> a -> b
$ String
"Invalid AuditLogAction: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Scientific -> String
forall a. Show a => a -> String
show Scientific
n

instance Aeson.ToJSON AuditLogAction where
  toJSON :: AuditLogAction -> Value
toJSON = forall a. ToJSON a => a -> Value
Aeson.toJSON @Int (Int -> Value)
-> (AuditLogAction -> Int) -> AuditLogAction -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AuditLogAction -> Int
forall a. Enum a => a -> Int
fromEnum
  toEncoding :: AuditLogAction -> Encoding
toEncoding = forall a. ToJSON a => a -> Encoding
Aeson.toEncoding @Int (Int -> Encoding)
-> (AuditLogAction -> Int) -> AuditLogAction -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AuditLogAction -> Int
forall a. Enum a => a -> Int
fromEnum

$(deriveTextShow ''AuditLogAction)
$(deriveTextShow ''AuditLogEntryInfo)
$(deriveTextShow ''AuditLogEntry)
$(deriveTextShow ''AuditLog)

$(makeFieldLabelsNoPrefix ''AuditLog)
$(makeFieldLabelsNoPrefix ''AuditLogEntry)
$(makeFieldLabelsNoPrefix ''AuditLogEntryInfo)
$(makeFieldLabelsNoPrefix ''AuditLogChange)