module TD.Query.SetChatAffiliateProgram
  (SetChatAffiliateProgram(..)
  , defaultSetChatAffiliateProgram
  ) 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.AffiliateProgramParameters as AffiliateProgramParameters

-- | Changes affiliate program for a bot. Returns 'TD.Data.Ok.Ok'
data SetChatAffiliateProgram
  = SetChatAffiliateProgram
    { SetChatAffiliateProgram -> Maybe Int
chat_id    :: Maybe Int                                                   -- ^ Identifier of the chat with an owned bot for which affiliate program is changed
    , SetChatAffiliateProgram -> Maybe AffiliateProgramParameters
parameters :: Maybe AffiliateProgramParameters.AffiliateProgramParameters -- ^ Parameters of the affiliate program; pass null to close the currently active program. If there is an active program, then commission and program duration can only be increased. If the active program is scheduled to be closed, then it can't be changed anymore
    }
  deriving (SetChatAffiliateProgram -> SetChatAffiliateProgram -> Bool
(SetChatAffiliateProgram -> SetChatAffiliateProgram -> Bool)
-> (SetChatAffiliateProgram -> SetChatAffiliateProgram -> Bool)
-> Eq SetChatAffiliateProgram
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetChatAffiliateProgram -> SetChatAffiliateProgram -> Bool
== :: SetChatAffiliateProgram -> SetChatAffiliateProgram -> Bool
$c/= :: SetChatAffiliateProgram -> SetChatAffiliateProgram -> Bool
/= :: SetChatAffiliateProgram -> SetChatAffiliateProgram -> Bool
Eq, Int -> SetChatAffiliateProgram -> ShowS
[SetChatAffiliateProgram] -> ShowS
SetChatAffiliateProgram -> String
(Int -> SetChatAffiliateProgram -> ShowS)
-> (SetChatAffiliateProgram -> String)
-> ([SetChatAffiliateProgram] -> ShowS)
-> Show SetChatAffiliateProgram
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetChatAffiliateProgram -> ShowS
showsPrec :: Int -> SetChatAffiliateProgram -> ShowS
$cshow :: SetChatAffiliateProgram -> String
show :: SetChatAffiliateProgram -> String
$cshowList :: [SetChatAffiliateProgram] -> ShowS
showList :: [SetChatAffiliateProgram] -> ShowS
Show)

instance I.ShortShow SetChatAffiliateProgram where
  shortShow :: SetChatAffiliateProgram -> String
shortShow
    SetChatAffiliateProgram
      { chat_id :: SetChatAffiliateProgram -> Maybe Int
chat_id    = Maybe Int
chat_id_
      , parameters :: SetChatAffiliateProgram -> Maybe AffiliateProgramParameters
parameters = Maybe AffiliateProgramParameters
parameters_
      }
        = String
"SetChatAffiliateProgram"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"chat_id"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
          , String
"parameters" String -> Maybe AffiliateProgramParameters -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe AffiliateProgramParameters
parameters_
          ]

instance AT.ToJSON SetChatAffiliateProgram where
  toJSON :: SetChatAffiliateProgram -> Value
toJSON
    SetChatAffiliateProgram
      { chat_id :: SetChatAffiliateProgram -> Maybe Int
chat_id    = Maybe Int
chat_id_
      , parameters :: SetChatAffiliateProgram -> Maybe AffiliateProgramParameters
parameters = Maybe AffiliateProgramParameters
parameters_
      }
        = [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
"setChatAffiliateProgram"
          , Key
"chat_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
chat_id_
          , Key
"parameters" Key -> Maybe AffiliateProgramParameters -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe AffiliateProgramParameters
parameters_
          ]

defaultSetChatAffiliateProgram :: SetChatAffiliateProgram
defaultSetChatAffiliateProgram :: SetChatAffiliateProgram
defaultSetChatAffiliateProgram =
  SetChatAffiliateProgram
    { chat_id :: Maybe Int
chat_id    = Maybe Int
forall a. Maybe a
Nothing
    , parameters :: Maybe AffiliateProgramParameters
parameters = Maybe AffiliateProgramParameters
forall a. Maybe a
Nothing
    }