module TD.Data.FoundAffiliateProgram
  (FoundAffiliateProgram(..)) 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.AffiliateProgramInfo as AffiliateProgramInfo

data FoundAffiliateProgram
  = FoundAffiliateProgram -- ^ Describes a found affiliate program
    { FoundAffiliateProgram -> Maybe Int
bot_user_id :: Maybe Int                                       -- ^ User identifier of the bot created the program
    , FoundAffiliateProgram -> Maybe AffiliateProgramInfo
info        :: Maybe AffiliateProgramInfo.AffiliateProgramInfo -- ^ Information about the affiliate program
    }
  deriving (FoundAffiliateProgram -> FoundAffiliateProgram -> Bool
(FoundAffiliateProgram -> FoundAffiliateProgram -> Bool)
-> (FoundAffiliateProgram -> FoundAffiliateProgram -> Bool)
-> Eq FoundAffiliateProgram
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FoundAffiliateProgram -> FoundAffiliateProgram -> Bool
== :: FoundAffiliateProgram -> FoundAffiliateProgram -> Bool
$c/= :: FoundAffiliateProgram -> FoundAffiliateProgram -> Bool
/= :: FoundAffiliateProgram -> FoundAffiliateProgram -> Bool
Eq, Int -> FoundAffiliateProgram -> ShowS
[FoundAffiliateProgram] -> ShowS
FoundAffiliateProgram -> String
(Int -> FoundAffiliateProgram -> ShowS)
-> (FoundAffiliateProgram -> String)
-> ([FoundAffiliateProgram] -> ShowS)
-> Show FoundAffiliateProgram
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FoundAffiliateProgram -> ShowS
showsPrec :: Int -> FoundAffiliateProgram -> ShowS
$cshow :: FoundAffiliateProgram -> String
show :: FoundAffiliateProgram -> String
$cshowList :: [FoundAffiliateProgram] -> ShowS
showList :: [FoundAffiliateProgram] -> ShowS
Show)

instance I.ShortShow FoundAffiliateProgram where
  shortShow :: FoundAffiliateProgram -> String
shortShow FoundAffiliateProgram
    { bot_user_id :: FoundAffiliateProgram -> Maybe Int
bot_user_id = Maybe Int
bot_user_id_
    , info :: FoundAffiliateProgram -> Maybe AffiliateProgramInfo
info        = Maybe AffiliateProgramInfo
info_
    }
      = String
"FoundAffiliateProgram"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"bot_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
bot_user_id_
        , String
"info"        String -> Maybe AffiliateProgramInfo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe AffiliateProgramInfo
info_
        ]

instance AT.FromJSON FoundAffiliateProgram where
  parseJSON :: Value -> Parser FoundAffiliateProgram
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
"foundAffiliateProgram" -> Value -> Parser FoundAffiliateProgram
parseFoundAffiliateProgram Value
v
      String
_                       -> Parser FoundAffiliateProgram
forall a. Monoid a => a
mempty
    
    where
      parseFoundAffiliateProgram :: A.Value -> AT.Parser FoundAffiliateProgram
      parseFoundAffiliateProgram :: Value -> Parser FoundAffiliateProgram
parseFoundAffiliateProgram = String
-> (Object -> Parser FoundAffiliateProgram)
-> Value
-> Parser FoundAffiliateProgram
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"FoundAffiliateProgram" ((Object -> Parser FoundAffiliateProgram)
 -> Value -> Parser FoundAffiliateProgram)
-> (Object -> Parser FoundAffiliateProgram)
-> Value
-> Parser FoundAffiliateProgram
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
bot_user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"bot_user_id"
        Maybe AffiliateProgramInfo
info_        <- Object
o Object -> Key -> Parser (Maybe AffiliateProgramInfo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"info"
        FoundAffiliateProgram -> Parser FoundAffiliateProgram
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (FoundAffiliateProgram -> Parser FoundAffiliateProgram)
-> FoundAffiliateProgram -> Parser FoundAffiliateProgram
forall a b. (a -> b) -> a -> b
$ FoundAffiliateProgram
          { bot_user_id :: Maybe Int
bot_user_id = Maybe Int
bot_user_id_
          , info :: Maybe AffiliateProgramInfo
info        = Maybe AffiliateProgramInfo
info_
          }
  parseJSON Value
_ = Parser FoundAffiliateProgram
forall a. Monoid a => a
mempty