{-# LANGUAGE TemplateHaskell #-}

module Calamity.Types.Model.Channel.Guild.Text (TextChannel (..)) where

import Calamity.Internal.SnowflakeMap (SnowflakeMap)
import {-# SOURCE #-} Calamity.Types.Model.Channel
import Calamity.Types.Model.Channel.Guild.Category
import Calamity.Types.Model.Channel.Message
import {-# SOURCE #-} Calamity.Types.Model.Guild.Guild
import Calamity.Types.Model.Guild.Overwrite
import Calamity.Types.Snowflake
import Data.Aeson ((.!=), (.:), (.:?))
import Data.Aeson qualified as Aeson
import Data.Text (Text)
import Data.Time
import Optics.TH
import TextShow qualified

data TextChannel = TextChannel
  { TextChannel -> Snowflake TextChannel
id :: Snowflake TextChannel
  , TextChannel -> Snowflake Guild
guildID :: Snowflake Guild
  , TextChannel -> Int
position :: Int
  , TextChannel -> SnowflakeMap Overwrite
permissionOverwrites :: SnowflakeMap Overwrite
  , TextChannel -> Text
name :: Text
  , TextChannel -> Maybe Text
topic :: Maybe Text
  , TextChannel -> Bool
nsfw :: Bool
  , TextChannel -> Maybe (Snowflake Message)
lastMessageID :: Maybe (Snowflake Message)
  , TextChannel -> Maybe UTCTime
lastPinTimestamp :: Maybe UTCTime
  , TextChannel -> Maybe Int
rateLimitPerUser :: Maybe Int
  , TextChannel -> Maybe (Snowflake Category)
parentID :: Maybe (Snowflake Category)
  }
  deriving (Int -> TextChannel -> ShowS
[TextChannel] -> ShowS
TextChannel -> String
(Int -> TextChannel -> ShowS)
-> (TextChannel -> String)
-> ([TextChannel] -> ShowS)
-> Show TextChannel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextChannel -> ShowS
showsPrec :: Int -> TextChannel -> ShowS
$cshow :: TextChannel -> String
show :: TextChannel -> String
$cshowList :: [TextChannel] -> ShowS
showList :: [TextChannel] -> ShowS
Show, TextChannel -> TextChannel -> Bool
(TextChannel -> TextChannel -> Bool)
-> (TextChannel -> TextChannel -> Bool) -> Eq TextChannel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextChannel -> TextChannel -> Bool
== :: TextChannel -> TextChannel -> Bool
$c/= :: TextChannel -> TextChannel -> Bool
/= :: TextChannel -> TextChannel -> Bool
Eq)
  deriving (Int -> TextChannel -> Text
Int -> TextChannel -> Builder
Int -> TextChannel -> Text
[TextChannel] -> Text
[TextChannel] -> Builder
[TextChannel] -> Text
TextChannel -> Text
TextChannel -> Builder
TextChannel -> Text
(Int -> TextChannel -> Builder)
-> (TextChannel -> Builder)
-> ([TextChannel] -> Builder)
-> (Int -> TextChannel -> Text)
-> (TextChannel -> Text)
-> ([TextChannel] -> Text)
-> (Int -> TextChannel -> Text)
-> (TextChannel -> Text)
-> ([TextChannel] -> Text)
-> TextShow TextChannel
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
$cshowbPrec :: Int -> TextChannel -> Builder
showbPrec :: Int -> TextChannel -> Builder
$cshowb :: TextChannel -> Builder
showb :: TextChannel -> Builder
$cshowbList :: [TextChannel] -> Builder
showbList :: [TextChannel] -> Builder
$cshowtPrec :: Int -> TextChannel -> Text
showtPrec :: Int -> TextChannel -> Text
$cshowt :: TextChannel -> Text
showt :: TextChannel -> Text
$cshowtList :: [TextChannel] -> Text
showtList :: [TextChannel] -> Text
$cshowtlPrec :: Int -> TextChannel -> Text
showtlPrec :: Int -> TextChannel -> Text
$cshowtl :: TextChannel -> Text
showtl :: TextChannel -> Text
$cshowtlList :: [TextChannel] -> Text
showtlList :: [TextChannel] -> Text
TextShow.TextShow) via TextShow.FromStringShow TextChannel
  deriving (HasID TextChannel) via HasIDField "id" TextChannel
  deriving (HasID Channel) via HasIDFieldCoerce' "id" TextChannel
  deriving (HasID Guild) via HasIDField "guildID" TextChannel

instance Aeson.FromJSON TextChannel where
  parseJSON :: Value -> Parser TextChannel
parseJSON = String
-> (Object -> Parser TextChannel) -> Value -> Parser TextChannel
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"TextChannel" ((Object -> Parser TextChannel) -> Value -> Parser TextChannel)
-> (Object -> Parser TextChannel) -> Value -> Parser TextChannel
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Snowflake TextChannel
-> Snowflake Guild
-> Int
-> SnowflakeMap Overwrite
-> Text
-> Maybe Text
-> Bool
-> Maybe (Snowflake Message)
-> Maybe UTCTime
-> Maybe Int
-> Maybe (Snowflake Category)
-> TextChannel
TextChannel
      (Snowflake TextChannel
 -> Snowflake Guild
 -> Int
 -> SnowflakeMap Overwrite
 -> Text
 -> Maybe Text
 -> Bool
 -> Maybe (Snowflake Message)
 -> Maybe UTCTime
 -> Maybe Int
 -> Maybe (Snowflake Category)
 -> TextChannel)
-> Parser (Snowflake TextChannel)
-> Parser
     (Snowflake Guild
      -> Int
      -> SnowflakeMap Overwrite
      -> Text
      -> Maybe Text
      -> Bool
      -> Maybe (Snowflake Message)
      -> Maybe UTCTime
      -> Maybe Int
      -> Maybe (Snowflake Category)
      -> TextChannel)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Snowflake TextChannel)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
      Parser
  (Snowflake Guild
   -> Int
   -> SnowflakeMap Overwrite
   -> Text
   -> Maybe Text
   -> Bool
   -> Maybe (Snowflake Message)
   -> Maybe UTCTime
   -> Maybe Int
   -> Maybe (Snowflake Category)
   -> TextChannel)
-> Parser (Snowflake Guild)
-> Parser
     (Int
      -> SnowflakeMap Overwrite
      -> Text
      -> Maybe Text
      -> Bool
      -> Maybe (Snowflake Message)
      -> Maybe UTCTime
      -> Maybe Int
      -> Maybe (Snowflake Category)
      -> TextChannel)
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 (Snowflake Guild)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id"
      Parser
  (Int
   -> SnowflakeMap Overwrite
   -> Text
   -> Maybe Text
   -> Bool
   -> Maybe (Snowflake Message)
   -> Maybe UTCTime
   -> Maybe Int
   -> Maybe (Snowflake Category)
   -> TextChannel)
-> Parser Int
-> Parser
     (SnowflakeMap Overwrite
      -> Text
      -> Maybe Text
      -> Bool
      -> Maybe (Snowflake Message)
      -> Maybe UTCTime
      -> Maybe Int
      -> Maybe (Snowflake Category)
      -> TextChannel)
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 Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"position"
      Parser
  (SnowflakeMap Overwrite
   -> Text
   -> Maybe Text
   -> Bool
   -> Maybe (Snowflake Message)
   -> Maybe UTCTime
   -> Maybe Int
   -> Maybe (Snowflake Category)
   -> TextChannel)
-> Parser (SnowflakeMap Overwrite)
-> Parser
     (Text
      -> Maybe Text
      -> Bool
      -> Maybe (Snowflake Message)
      -> Maybe UTCTime
      -> Maybe Int
      -> Maybe (Snowflake Category)
      -> TextChannel)
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 (SnowflakeMap Overwrite)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"permission_overwrites"
      Parser
  (Text
   -> Maybe Text
   -> Bool
   -> Maybe (Snowflake Message)
   -> Maybe UTCTime
   -> Maybe Int
   -> Maybe (Snowflake Category)
   -> TextChannel)
-> Parser Text
-> Parser
     (Maybe Text
      -> Bool
      -> Maybe (Snowflake Message)
      -> Maybe UTCTime
      -> Maybe Int
      -> Maybe (Snowflake Category)
      -> TextChannel)
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 Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
      Parser
  (Maybe Text
   -> Bool
   -> Maybe (Snowflake Message)
   -> Maybe UTCTime
   -> Maybe Int
   -> Maybe (Snowflake Category)
   -> TextChannel)
-> Parser (Maybe Text)
-> Parser
     (Bool
      -> Maybe (Snowflake Message)
      -> Maybe UTCTime
      -> Maybe Int
      -> Maybe (Snowflake Category)
      -> TextChannel)
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 Text)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"topic"
      Parser
  (Bool
   -> Maybe (Snowflake Message)
   -> Maybe UTCTime
   -> Maybe Int
   -> Maybe (Snowflake Category)
   -> TextChannel)
-> Parser Bool
-> Parser
     (Maybe (Snowflake Message)
      -> Maybe UTCTime
      -> Maybe Int
      -> Maybe (Snowflake Category)
      -> TextChannel)
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
"nsfw" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
      Parser
  (Maybe (Snowflake Message)
   -> Maybe UTCTime
   -> Maybe Int
   -> Maybe (Snowflake Category)
   -> TextChannel)
-> Parser (Maybe (Snowflake Message))
-> Parser
     (Maybe UTCTime
      -> Maybe Int -> Maybe (Snowflake Category) -> TextChannel)
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 (Snowflake Message))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"last_message_id"
      Parser
  (Maybe UTCTime
   -> Maybe Int -> Maybe (Snowflake Category) -> TextChannel)
-> Parser (Maybe UTCTime)
-> Parser (Maybe Int -> Maybe (Snowflake Category) -> TextChannel)
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 UTCTime)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"last_pin_timestamp"
      Parser (Maybe Int -> Maybe (Snowflake Category) -> TextChannel)
-> Parser (Maybe Int)
-> Parser (Maybe (Snowflake Category) -> TextChannel)
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 Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"rate_limit_per_user"
      Parser (Maybe (Snowflake Category) -> TextChannel)
-> Parser (Maybe (Snowflake Category)) -> Parser TextChannel
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 (Snowflake Category))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"parent_id"

$(makeFieldLabelsNoPrefix ''TextChannel)