{-# LANGUAGE TemplateHaskell #-}

-- | Guilds that are unavailable
module Calamity.Types.Model.Guild.UnavailableGuild (UnavailableGuild (..)) where

import Calamity.Internal.Utils
import Calamity.Types.Model.Guild.Guild
import Calamity.Types.Snowflake
import Data.Aeson ((.!=), (.:), (.:?))
import Data.Aeson qualified as Aeson
import Optics.TH
import TextShow.TH

data UnavailableGuild = UnavailableGuild
  { UnavailableGuild -> Snowflake Guild
id :: Snowflake Guild
  , UnavailableGuild -> Bool
unavailable :: Bool
  }
  deriving (UnavailableGuild -> UnavailableGuild -> Bool
(UnavailableGuild -> UnavailableGuild -> Bool)
-> (UnavailableGuild -> UnavailableGuild -> Bool)
-> Eq UnavailableGuild
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UnavailableGuild -> UnavailableGuild -> Bool
== :: UnavailableGuild -> UnavailableGuild -> Bool
$c/= :: UnavailableGuild -> UnavailableGuild -> Bool
/= :: UnavailableGuild -> UnavailableGuild -> Bool
Eq, Int -> UnavailableGuild -> ShowS
[UnavailableGuild] -> ShowS
UnavailableGuild -> String
(Int -> UnavailableGuild -> ShowS)
-> (UnavailableGuild -> String)
-> ([UnavailableGuild] -> ShowS)
-> Show UnavailableGuild
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UnavailableGuild -> ShowS
showsPrec :: Int -> UnavailableGuild -> ShowS
$cshow :: UnavailableGuild -> String
show :: UnavailableGuild -> String
$cshowList :: [UnavailableGuild] -> ShowS
showList :: [UnavailableGuild] -> ShowS
Show)
  deriving (HasID Guild) via HasIDField "id" UnavailableGuild
  deriving ([UnavailableGuild] -> Value
[UnavailableGuild] -> Encoding
UnavailableGuild -> Value
UnavailableGuild -> Encoding
(UnavailableGuild -> Value)
-> (UnavailableGuild -> Encoding)
-> ([UnavailableGuild] -> Value)
-> ([UnavailableGuild] -> Encoding)
-> ToJSON UnavailableGuild
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: UnavailableGuild -> Value
toJSON :: UnavailableGuild -> Value
$ctoEncoding :: UnavailableGuild -> Encoding
toEncoding :: UnavailableGuild -> Encoding
$ctoJSONList :: [UnavailableGuild] -> Value
toJSONList :: [UnavailableGuild] -> Value
$ctoEncodingList :: [UnavailableGuild] -> Encoding
toEncodingList :: [UnavailableGuild] -> Encoding
Aeson.ToJSON) via CalamityToJSON UnavailableGuild

instance CalamityToJSON' UnavailableGuild where
  toPairs :: forall kv. KeyValue kv => UnavailableGuild -> [Maybe kv]
toPairs UnavailableGuild {Bool
Snowflake Guild
$sel:id:UnavailableGuild :: UnavailableGuild -> Snowflake Guild
$sel:unavailable:UnavailableGuild :: UnavailableGuild -> Bool
id :: Snowflake Guild
unavailable :: Bool
..} =
    [ Key
"id" Key -> Snowflake Guild -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Snowflake Guild
id
    , Key
"unavailable" Key -> Bool -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Bool
unavailable
    ]

instance Aeson.FromJSON UnavailableGuild where
  parseJSON :: Value -> Parser UnavailableGuild
parseJSON = String
-> (Object -> Parser UnavailableGuild)
-> Value
-> Parser UnavailableGuild
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"UnavailableGuild" ((Object -> Parser UnavailableGuild)
 -> Value -> Parser UnavailableGuild)
-> (Object -> Parser UnavailableGuild)
-> Value
-> Parser UnavailableGuild
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Snowflake Guild -> Bool -> UnavailableGuild
UnavailableGuild
      (Snowflake Guild -> Bool -> UnavailableGuild)
-> Parser (Snowflake Guild) -> Parser (Bool -> UnavailableGuild)
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
"id"
      Parser (Bool -> UnavailableGuild)
-> Parser Bool -> Parser UnavailableGuild
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 (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"disabled" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False

$(deriveTextShow ''UnavailableGuild)
$(makeFieldLabelsNoPrefix ''UnavailableGuild)