{-# LANGUAGE TemplateHaskell #-}
module Calamity.Types.Model.Channel.Attachment (
Attachment (..),
) where
import Calamity.Types.Snowflake
import Data.Aeson ((.:), (.:?))
import qualified Data.Aeson as Aeson
import Data.Text (Text)
import Data.Word
import Optics.TH
import TextShow.TH
fuseTup2 :: Monad f => (f a, f b) -> f (a, b)
fuseTup2 :: forall (f :: * -> *) a b. Monad f => (f a, f b) -> f (a, b)
fuseTup2 (f a
a, f b
b) = do
!a
a' <- f a
a
!b
b' <- f b
b
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a
a', b
b')
data Attachment = Attachment
{ Attachment -> Snowflake Attachment
id :: Snowflake Attachment
, Attachment -> Text
filename :: Text
, Attachment -> Word64
size :: Word64
, Attachment -> Text
url :: Text
, Attachment -> Text
proxyUrl :: Text
, Attachment -> Maybe (Word64, Word64)
dimensions :: Maybe (Word64, Word64)
}
deriving (Attachment -> Attachment -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Attachment -> Attachment -> Bool
$c/= :: Attachment -> Attachment -> Bool
== :: Attachment -> Attachment -> Bool
$c== :: Attachment -> Attachment -> Bool
Eq, Int -> Attachment -> ShowS
[Attachment] -> ShowS
Attachment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Attachment] -> ShowS
$cshowList :: [Attachment] -> ShowS
show :: Attachment -> String
$cshow :: Attachment -> String
showsPrec :: Int -> Attachment -> ShowS
$cshowsPrec :: Int -> Attachment -> ShowS
Show)
deriving (HasID Attachment) via HasIDField "id" Attachment
$(deriveTextShow ''Attachment)
$(makeFieldLabelsNoPrefix ''Attachment)
instance Aeson.FromJSON Attachment where
parseJSON :: Value -> Parser Attachment
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Attachment" forall a b. (a -> b) -> a -> b
$ \Object
v -> do
Maybe Word64
width <- Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"width"
Maybe Word64
height <- Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"height"
Snowflake Attachment
-> Text
-> Word64
-> Text
-> Text
-> Maybe (Word64, Word64)
-> Attachment
Attachment
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"filename"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"size"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"url"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"proxy_url"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure
(forall (f :: * -> *) a b. Monad f => (f a, f b) -> f (a, b)
fuseTup2 (Maybe Word64
width, Maybe Word64
height))