module TD.Query.SendGift
  (SendGift(..)
  , defaultSendGift
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.FormattedText as FormattedText

-- | Sends a gift to another user. May return an error with a message "STARGIFT_USAGE_LIMITED" if the gift was sold out. Returns 'TD.Data.Ok.Ok'
data SendGift
  = SendGift
    { SendGift -> Maybe Int
gift_id    :: Maybe Int                         -- ^ Identifier of the gift to send
    , SendGift -> Maybe Int
user_id    :: Maybe Int                         -- ^ Identifier of the user that will receive the gift
    , SendGift -> Maybe FormattedText
text       :: Maybe FormattedText.FormattedText -- ^ Text to show along with the gift; 0-getOption("gift_text_length_max") characters. Only Bold, Italic, Underline, Strikethrough, Spoiler, and CustomEmoji entities are allowed
    , SendGift -> Maybe Bool
is_private :: Maybe Bool                        -- ^ Pass true to show the current user as sender and gift text only to the gift receiver; otherwise, everyone will be able to see them
    }
  deriving (SendGift -> SendGift -> Bool
(SendGift -> SendGift -> Bool)
-> (SendGift -> SendGift -> Bool) -> Eq SendGift
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SendGift -> SendGift -> Bool
== :: SendGift -> SendGift -> Bool
$c/= :: SendGift -> SendGift -> Bool
/= :: SendGift -> SendGift -> Bool
Eq, Int -> SendGift -> ShowS
[SendGift] -> ShowS
SendGift -> String
(Int -> SendGift -> ShowS)
-> (SendGift -> String) -> ([SendGift] -> ShowS) -> Show SendGift
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SendGift -> ShowS
showsPrec :: Int -> SendGift -> ShowS
$cshow :: SendGift -> String
show :: SendGift -> String
$cshowList :: [SendGift] -> ShowS
showList :: [SendGift] -> ShowS
Show)

instance I.ShortShow SendGift where
  shortShow :: SendGift -> String
shortShow
    SendGift
      { gift_id :: SendGift -> Maybe Int
gift_id    = Maybe Int
gift_id_
      , user_id :: SendGift -> Maybe Int
user_id    = Maybe Int
user_id_
      , text :: SendGift -> Maybe FormattedText
text       = Maybe FormattedText
text_
      , is_private :: SendGift -> Maybe Bool
is_private = Maybe Bool
is_private_
      }
        = String
"SendGift"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"gift_id"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
gift_id_
          , String
"user_id"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
          , String
"text"       String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
text_
          , String
"is_private" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_private_
          ]

instance AT.ToJSON SendGift where
  toJSON :: SendGift -> Value
toJSON
    SendGift
      { gift_id :: SendGift -> Maybe Int
gift_id    = Maybe Int
gift_id_
      , user_id :: SendGift -> Maybe Int
user_id    = Maybe Int
user_id_
      , text :: SendGift -> Maybe FormattedText
text       = Maybe FormattedText
text_
      , is_private :: SendGift -> Maybe Bool
is_private = Maybe Bool
is_private_
      }
        = [Pair] -> Value
A.object
          [ Key
"@type"      Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"sendGift"
          , Key
"gift_id"    Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (Int -> Value) -> Maybe Int -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Value
I.writeInt64  Maybe Int
gift_id_
          , Key
"user_id"    Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
user_id_
          , Key
"text"       Key -> Maybe FormattedText -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe FormattedText
text_
          , Key
"is_private" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_private_
          ]

defaultSendGift :: SendGift
defaultSendGift :: SendGift
defaultSendGift =
  SendGift
    { gift_id :: Maybe Int
gift_id    = Maybe Int
forall a. Maybe a
Nothing
    , user_id :: Maybe Int
user_id    = Maybe Int
forall a. Maybe a
Nothing
    , text :: Maybe FormattedText
text       = Maybe FormattedText
forall a. Maybe a
Nothing
    , is_private :: Maybe Bool
is_private = Maybe Bool
forall a. Maybe a
Nothing
    }