module TD.Data.ConnectedAffiliatePrograms
  (ConnectedAffiliatePrograms(..)) 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.ConnectedAffiliateProgram as ConnectedAffiliateProgram
import qualified Data.Text as T

data ConnectedAffiliatePrograms
  = ConnectedAffiliatePrograms -- ^ Represents a list of affiliate programs that were connected to an affiliate
    { ConnectedAffiliatePrograms -> Maybe Int
total_count :: Maybe Int                                                   -- ^ The total number of affiliate programs that were connected to the affiliate
    , ConnectedAffiliatePrograms -> Maybe [ConnectedAffiliateProgram]
programs    :: Maybe [ConnectedAffiliateProgram.ConnectedAffiliateProgram] -- ^ The list of connected affiliate programs
    , ConnectedAffiliatePrograms -> Maybe Text
next_offset :: Maybe T.Text                                                -- ^ The offset for the next request. If empty, then there are no more results
    }
  deriving (ConnectedAffiliatePrograms -> ConnectedAffiliatePrograms -> Bool
(ConnectedAffiliatePrograms -> ConnectedAffiliatePrograms -> Bool)
-> (ConnectedAffiliatePrograms
    -> ConnectedAffiliatePrograms -> Bool)
-> Eq ConnectedAffiliatePrograms
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConnectedAffiliatePrograms -> ConnectedAffiliatePrograms -> Bool
== :: ConnectedAffiliatePrograms -> ConnectedAffiliatePrograms -> Bool
$c/= :: ConnectedAffiliatePrograms -> ConnectedAffiliatePrograms -> Bool
/= :: ConnectedAffiliatePrograms -> ConnectedAffiliatePrograms -> Bool
Eq, Int -> ConnectedAffiliatePrograms -> ShowS
[ConnectedAffiliatePrograms] -> ShowS
ConnectedAffiliatePrograms -> String
(Int -> ConnectedAffiliatePrograms -> ShowS)
-> (ConnectedAffiliatePrograms -> String)
-> ([ConnectedAffiliatePrograms] -> ShowS)
-> Show ConnectedAffiliatePrograms
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConnectedAffiliatePrograms -> ShowS
showsPrec :: Int -> ConnectedAffiliatePrograms -> ShowS
$cshow :: ConnectedAffiliatePrograms -> String
show :: ConnectedAffiliatePrograms -> String
$cshowList :: [ConnectedAffiliatePrograms] -> ShowS
showList :: [ConnectedAffiliatePrograms] -> ShowS
Show)

instance I.ShortShow ConnectedAffiliatePrograms where
  shortShow :: ConnectedAffiliatePrograms -> String
shortShow ConnectedAffiliatePrograms
    { total_count :: ConnectedAffiliatePrograms -> Maybe Int
total_count = Maybe Int
total_count_
    , programs :: ConnectedAffiliatePrograms -> Maybe [ConnectedAffiliateProgram]
programs    = Maybe [ConnectedAffiliateProgram]
programs_
    , next_offset :: ConnectedAffiliatePrograms -> Maybe Text
next_offset = Maybe Text
next_offset_
    }
      = String
"ConnectedAffiliatePrograms"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"total_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_count_
        , String
"programs"    String -> Maybe [ConnectedAffiliateProgram] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [ConnectedAffiliateProgram]
programs_
        , String
"next_offset" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
next_offset_
        ]

instance AT.FromJSON ConnectedAffiliatePrograms where
  parseJSON :: Value -> Parser ConnectedAffiliatePrograms
parseJSON v :: Value
v@(AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"connectedAffiliatePrograms" -> Value -> Parser ConnectedAffiliatePrograms
parseConnectedAffiliatePrograms Value
v
      String
_                            -> Parser ConnectedAffiliatePrograms
forall a. Monoid a => a
mempty
    
    where
      parseConnectedAffiliatePrograms :: A.Value -> AT.Parser ConnectedAffiliatePrograms
      parseConnectedAffiliatePrograms :: Value -> Parser ConnectedAffiliatePrograms
parseConnectedAffiliatePrograms = String
-> (Object -> Parser ConnectedAffiliatePrograms)
-> Value
-> Parser ConnectedAffiliatePrograms
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ConnectedAffiliatePrograms" ((Object -> Parser ConnectedAffiliatePrograms)
 -> Value -> Parser ConnectedAffiliatePrograms)
-> (Object -> Parser ConnectedAffiliatePrograms)
-> Value
-> Parser ConnectedAffiliatePrograms
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
total_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"total_count"
        Maybe [ConnectedAffiliateProgram]
programs_    <- Object
o Object -> Key -> Parser (Maybe [ConnectedAffiliateProgram])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"programs"
        Maybe Text
next_offset_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"next_offset"
        ConnectedAffiliatePrograms -> Parser ConnectedAffiliatePrograms
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ConnectedAffiliatePrograms -> Parser ConnectedAffiliatePrograms)
-> ConnectedAffiliatePrograms -> Parser ConnectedAffiliatePrograms
forall a b. (a -> b) -> a -> b
$ ConnectedAffiliatePrograms
          { total_count :: Maybe Int
total_count = Maybe Int
total_count_
          , programs :: Maybe [ConnectedAffiliateProgram]
programs    = Maybe [ConnectedAffiliateProgram]
programs_
          , next_offset :: Maybe Text
next_offset = Maybe Text
next_offset_
          }
  parseJSON Value
_ = Parser ConnectedAffiliatePrograms
forall a. Monoid a => a
mempty