module TD.Query.SearchAffiliatePrograms
  (SearchAffiliatePrograms(..)
  , defaultSearchAffiliatePrograms
  ) 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.AffiliateType as AffiliateType
import qualified TD.Data.AffiliateProgramSortOrder as AffiliateProgramSortOrder
import qualified Data.Text as T

-- | Searches affiliate programs that can be connected to the given affiliate. Returns 'TD.Data.FoundAffiliatePrograms.FoundAffiliatePrograms'
data SearchAffiliatePrograms
  = SearchAffiliatePrograms
    { SearchAffiliatePrograms -> Maybe AffiliateType
affiliate  :: Maybe AffiliateType.AffiliateType                         -- ^ The affiliate for which affiliate programs are searched for
    , SearchAffiliatePrograms -> Maybe AffiliateProgramSortOrder
sort_order :: Maybe AffiliateProgramSortOrder.AffiliateProgramSortOrder -- ^ Sort order for the results
    , SearchAffiliatePrograms -> Maybe Text
offset     :: Maybe T.Text                                              -- ^ Offset of the first affiliate program to return as received from the previous request; use empty string to get the first chunk of results
    , SearchAffiliatePrograms -> Maybe Int
limit      :: Maybe Int                                                 -- ^ The maximum number of affiliate programs to return
    }
  deriving (SearchAffiliatePrograms -> SearchAffiliatePrograms -> Bool
(SearchAffiliatePrograms -> SearchAffiliatePrograms -> Bool)
-> (SearchAffiliatePrograms -> SearchAffiliatePrograms -> Bool)
-> Eq SearchAffiliatePrograms
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SearchAffiliatePrograms -> SearchAffiliatePrograms -> Bool
== :: SearchAffiliatePrograms -> SearchAffiliatePrograms -> Bool
$c/= :: SearchAffiliatePrograms -> SearchAffiliatePrograms -> Bool
/= :: SearchAffiliatePrograms -> SearchAffiliatePrograms -> Bool
Eq, Int -> SearchAffiliatePrograms -> ShowS
[SearchAffiliatePrograms] -> ShowS
SearchAffiliatePrograms -> String
(Int -> SearchAffiliatePrograms -> ShowS)
-> (SearchAffiliatePrograms -> String)
-> ([SearchAffiliatePrograms] -> ShowS)
-> Show SearchAffiliatePrograms
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SearchAffiliatePrograms -> ShowS
showsPrec :: Int -> SearchAffiliatePrograms -> ShowS
$cshow :: SearchAffiliatePrograms -> String
show :: SearchAffiliatePrograms -> String
$cshowList :: [SearchAffiliatePrograms] -> ShowS
showList :: [SearchAffiliatePrograms] -> ShowS
Show)

instance I.ShortShow SearchAffiliatePrograms where
  shortShow :: SearchAffiliatePrograms -> String
shortShow
    SearchAffiliatePrograms
      { affiliate :: SearchAffiliatePrograms -> Maybe AffiliateType
affiliate  = Maybe AffiliateType
affiliate_
      , sort_order :: SearchAffiliatePrograms -> Maybe AffiliateProgramSortOrder
sort_order = Maybe AffiliateProgramSortOrder
sort_order_
      , offset :: SearchAffiliatePrograms -> Maybe Text
offset     = Maybe Text
offset_
      , limit :: SearchAffiliatePrograms -> Maybe Int
limit      = Maybe Int
limit_
      }
        = String
"SearchAffiliatePrograms"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"affiliate"  String -> Maybe AffiliateType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe AffiliateType
affiliate_
          , String
"sort_order" String -> Maybe AffiliateProgramSortOrder -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe AffiliateProgramSortOrder
sort_order_
          , String
"offset"     String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
offset_
          , String
"limit"      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
limit_
          ]

instance AT.ToJSON SearchAffiliatePrograms where
  toJSON :: SearchAffiliatePrograms -> Value
toJSON
    SearchAffiliatePrograms
      { affiliate :: SearchAffiliatePrograms -> Maybe AffiliateType
affiliate  = Maybe AffiliateType
affiliate_
      , sort_order :: SearchAffiliatePrograms -> Maybe AffiliateProgramSortOrder
sort_order = Maybe AffiliateProgramSortOrder
sort_order_
      , offset :: SearchAffiliatePrograms -> Maybe Text
offset     = Maybe Text
offset_
      , limit :: SearchAffiliatePrograms -> Maybe Int
limit      = Maybe Int
limit_
      }
        = [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
"searchAffiliatePrograms"
          , Key
"affiliate"  Key -> Maybe AffiliateType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe AffiliateType
affiliate_
          , Key
"sort_order" Key -> Maybe AffiliateProgramSortOrder -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe AffiliateProgramSortOrder
sort_order_
          , Key
"offset"     Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
offset_
          , Key
"limit"      Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
limit_
          ]

defaultSearchAffiliatePrograms :: SearchAffiliatePrograms
defaultSearchAffiliatePrograms :: SearchAffiliatePrograms
defaultSearchAffiliatePrograms =
  SearchAffiliatePrograms
    { affiliate :: Maybe AffiliateType
affiliate  = Maybe AffiliateType
forall a. Maybe a
Nothing
    , sort_order :: Maybe AffiliateProgramSortOrder
sort_order = Maybe AffiliateProgramSortOrder
forall a. Maybe a
Nothing
    , offset :: Maybe Text
offset     = Maybe Text
forall a. Maybe a
Nothing
    , limit :: Maybe Int
limit      = Maybe Int
forall a. Maybe a
Nothing
    }