module TD.Query.SearchChatAffiliateProgram
  (SearchChatAffiliateProgram(..)
  , defaultSearchChatAffiliateProgram
  ) where

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

-- | Searches a chat with an affiliate program. Returns the chat if found and the program is active. Returns 'TD.Data.Chat.Chat'
data SearchChatAffiliateProgram
  = SearchChatAffiliateProgram
    { SearchChatAffiliateProgram -> Maybe Text
username :: Maybe T.Text -- ^ Username of the chat
    , SearchChatAffiliateProgram -> Maybe Text
referrer :: Maybe T.Text -- ^ The referrer from an internalLinkTypeChatAffiliateProgram link
    }
  deriving (SearchChatAffiliateProgram -> SearchChatAffiliateProgram -> Bool
(SearchChatAffiliateProgram -> SearchChatAffiliateProgram -> Bool)
-> (SearchChatAffiliateProgram
    -> SearchChatAffiliateProgram -> Bool)
-> Eq SearchChatAffiliateProgram
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SearchChatAffiliateProgram -> SearchChatAffiliateProgram -> Bool
== :: SearchChatAffiliateProgram -> SearchChatAffiliateProgram -> Bool
$c/= :: SearchChatAffiliateProgram -> SearchChatAffiliateProgram -> Bool
/= :: SearchChatAffiliateProgram -> SearchChatAffiliateProgram -> Bool
Eq, Int -> SearchChatAffiliateProgram -> ShowS
[SearchChatAffiliateProgram] -> ShowS
SearchChatAffiliateProgram -> String
(Int -> SearchChatAffiliateProgram -> ShowS)
-> (SearchChatAffiliateProgram -> String)
-> ([SearchChatAffiliateProgram] -> ShowS)
-> Show SearchChatAffiliateProgram
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SearchChatAffiliateProgram -> ShowS
showsPrec :: Int -> SearchChatAffiliateProgram -> ShowS
$cshow :: SearchChatAffiliateProgram -> String
show :: SearchChatAffiliateProgram -> String
$cshowList :: [SearchChatAffiliateProgram] -> ShowS
showList :: [SearchChatAffiliateProgram] -> ShowS
Show)

instance I.ShortShow SearchChatAffiliateProgram where
  shortShow :: SearchChatAffiliateProgram -> String
shortShow
    SearchChatAffiliateProgram
      { username :: SearchChatAffiliateProgram -> Maybe Text
username = Maybe Text
username_
      , referrer :: SearchChatAffiliateProgram -> Maybe Text
referrer = Maybe Text
referrer_
      }
        = String
"SearchChatAffiliateProgram"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"username" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
username_
          , String
"referrer" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
referrer_
          ]

instance AT.ToJSON SearchChatAffiliateProgram where
  toJSON :: SearchChatAffiliateProgram -> Value
toJSON
    SearchChatAffiliateProgram
      { username :: SearchChatAffiliateProgram -> Maybe Text
username = Maybe Text
username_
      , referrer :: SearchChatAffiliateProgram -> Maybe Text
referrer = Maybe Text
referrer_
      }
        = [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
"searchChatAffiliateProgram"
          , Key
"username" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
username_
          , Key
"referrer" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
referrer_
          ]

defaultSearchChatAffiliateProgram :: SearchChatAffiliateProgram
defaultSearchChatAffiliateProgram :: SearchChatAffiliateProgram
defaultSearchChatAffiliateProgram =
  SearchChatAffiliateProgram
    { username :: Maybe Text
username = Maybe Text
forall a. Maybe a
Nothing
    , referrer :: Maybe Text
referrer = Maybe Text
forall a. Maybe a
Nothing
    }