{-# LANGUAGE TemplateHaskell #-}

-- | Guild ban objects
module Calamity.Types.Model.Guild.Ban (BanData (..)) where

import Calamity.Types.Model.Guild.Guild
import Calamity.Types.Model.User
import Calamity.Types.Snowflake
import Data.Aeson ((.:))
import Data.Aeson qualified as Aeson
import Optics.TH
import TextShow.TH

data BanData = BanData
  { BanData -> Snowflake Guild
guildID :: Snowflake Guild
  , BanData -> User
user :: User
  }
  deriving (Int -> BanData -> ShowS
[BanData] -> ShowS
BanData -> String
(Int -> BanData -> ShowS)
-> (BanData -> String) -> ([BanData] -> ShowS) -> Show BanData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BanData -> ShowS
showsPrec :: Int -> BanData -> ShowS
$cshow :: BanData -> String
show :: BanData -> String
$cshowList :: [BanData] -> ShowS
showList :: [BanData] -> ShowS
Show)
  deriving (HasID Guild) via HasIDField "guildID" BanData
  deriving (HasID User) via HasIDField "user" BanData

instance Aeson.FromJSON BanData where
  parseJSON :: Value -> Parser BanData
parseJSON = String -> (Object -> Parser BanData) -> Value -> Parser BanData
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"BanData" ((Object -> Parser BanData) -> Value -> Parser BanData)
-> (Object -> Parser BanData) -> Value -> Parser BanData
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Snowflake Guild -> User -> BanData
BanData
      (Snowflake Guild -> User -> BanData)
-> Parser (Snowflake Guild) -> Parser (User -> BanData)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Snowflake Guild)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id"
      Parser (User -> BanData) -> Parser User -> Parser BanData
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser User
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"user"

$(deriveTextShow ''BanData)
$(makeFieldLabelsNoPrefix ''BanData)