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

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

instance I.ShortShow FoundAffiliatePrograms where
  shortShow :: FoundAffiliatePrograms -> String
shortShow FoundAffiliatePrograms
    { total_count :: FoundAffiliatePrograms -> Maybe Int
total_count = Maybe Int
total_count_
    , programs :: FoundAffiliatePrograms -> Maybe [FoundAffiliateProgram]
programs    = Maybe [FoundAffiliateProgram]
programs_
    , next_offset :: FoundAffiliatePrograms -> Maybe Text
next_offset = Maybe Text
next_offset_
    }
      = String
"FoundAffiliatePrograms"
        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 [FoundAffiliateProgram] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [FoundAffiliateProgram]
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 FoundAffiliatePrograms where
  parseJSON :: Value -> Parser FoundAffiliatePrograms
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
"foundAffiliatePrograms" -> Value -> Parser FoundAffiliatePrograms
parseFoundAffiliatePrograms Value
v
      String
_                        -> Parser FoundAffiliatePrograms
forall a. Monoid a => a
mempty
    
    where
      parseFoundAffiliatePrograms :: A.Value -> AT.Parser FoundAffiliatePrograms
      parseFoundAffiliatePrograms :: Value -> Parser FoundAffiliatePrograms
parseFoundAffiliatePrograms = String
-> (Object -> Parser FoundAffiliatePrograms)
-> Value
-> Parser FoundAffiliatePrograms
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"FoundAffiliatePrograms" ((Object -> Parser FoundAffiliatePrograms)
 -> Value -> Parser FoundAffiliatePrograms)
-> (Object -> Parser FoundAffiliatePrograms)
-> Value
-> Parser FoundAffiliatePrograms
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 [FoundAffiliateProgram]
programs_    <- Object
o Object -> Key -> Parser (Maybe [FoundAffiliateProgram])
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"
        FoundAffiliatePrograms -> Parser FoundAffiliatePrograms
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (FoundAffiliatePrograms -> Parser FoundAffiliatePrograms)
-> FoundAffiliatePrograms -> Parser FoundAffiliatePrograms
forall a b. (a -> b) -> a -> b
$ FoundAffiliatePrograms
          { total_count :: Maybe Int
total_count = Maybe Int
total_count_
          , programs :: Maybe [FoundAffiliateProgram]
programs    = Maybe [FoundAffiliateProgram]
programs_
          , next_offset :: Maybe Text
next_offset = Maybe Text
next_offset_
          }
  parseJSON Value
_ = Parser FoundAffiliatePrograms
forall a. Monoid a => a
mempty