{-# LANGUAGE TemplateHaskell #-}

-- | Guild invites
module Calamity.Types.Model.Guild.Invite (Invite (..)) where

import Calamity.Types.Model.Channel
import Calamity.Types.Model.Guild.Guild
import Calamity.Types.Model.User
import Data.Aeson ((.:), (.:?))
import qualified Data.Aeson as Aeson
import Data.Text (Text)
import Data.Time (UTCTime)
import Optics.TH
import qualified TextShow

data Invite = Invite
  { Invite -> Text
code :: Text
  , Invite -> Maybe (Partial Guild)
guild :: Maybe (Partial Guild)
  , Invite -> Maybe (Partial Channel)
channel :: Maybe (Partial Channel)
  , Invite -> Maybe User
inviter :: Maybe User
  , Invite -> Maybe User
targetUser :: Maybe User
  , Invite -> Maybe Int
targetType :: Maybe Int
  , Invite -> Maybe Int
approximatePresenceCount :: Maybe Int
  , Invite -> Maybe Int
approximateMemberCount :: Maybe Int
  , Invite -> Maybe UTCTime
expiresAt :: Maybe UTCTime
  }
  deriving (Invite -> Invite -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Invite -> Invite -> Bool
$c/= :: Invite -> Invite -> Bool
== :: Invite -> Invite -> Bool
$c== :: Invite -> Invite -> Bool
Eq, Int -> Invite -> ShowS
[Invite] -> ShowS
Invite -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Invite] -> ShowS
$cshowList :: [Invite] -> ShowS
show :: Invite -> String
$cshow :: Invite -> String
showsPrec :: Int -> Invite -> ShowS
$cshowsPrec :: Int -> Invite -> ShowS
Show)
  deriving (Int -> Invite -> Builder
Int -> Invite -> Text
Int -> Invite -> Text
[Invite] -> Builder
[Invite] -> Text
[Invite] -> Text
Invite -> Builder
Invite -> Text
Invite -> Text
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 :: [Invite] -> Text
$cshowtlList :: [Invite] -> Text
showtl :: Invite -> Text
$cshowtl :: Invite -> Text
showtlPrec :: Int -> Invite -> Text
$cshowtlPrec :: Int -> Invite -> Text
showtList :: [Invite] -> Text
$cshowtList :: [Invite] -> Text
showt :: Invite -> Text
$cshowt :: Invite -> Text
showtPrec :: Int -> Invite -> Text
$cshowtPrec :: Int -> Invite -> Text
showbList :: [Invite] -> Builder
$cshowbList :: [Invite] -> Builder
showb :: Invite -> Builder
$cshowb :: Invite -> Builder
showbPrec :: Int -> Invite -> Builder
$cshowbPrec :: Int -> Invite -> Builder
TextShow.TextShow) via TextShow.FromStringShow Invite

instance Aeson.FromJSON Invite where
  parseJSON :: Value -> Parser Invite
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Invite" forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Text
-> Maybe (Partial Guild)
-> Maybe (Partial Channel)
-> Maybe User
-> Maybe User
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe UTCTime
-> Invite
Invite
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"code"
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"guild"
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"channel"
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"inviter"
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"target_user"
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"target_type"
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"approximate_presence_count"
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"approximate_user_count"
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"expires_at"

$(makeFieldLabelsNoPrefix ''Invite)