module TD.Data.ReportChatResult
  (ReportChatResult(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
import qualified TD.Data.ReportOption as ReportOption
import qualified Data.ByteString as BS

-- | Describes result of chat report
data ReportChatResult
  = ReportChatResultOk -- ^ The chat was reported successfully
  | ReportChatResultOptionRequired -- ^ The user must choose an option to report the chat and repeat request with the chosen option
    { ReportChatResult -> Maybe Text
title   :: Maybe T.Text                      -- ^ Title for the option choice
    , ReportChatResult -> Maybe [ReportOption]
options :: Maybe [ReportOption.ReportOption] -- ^ List of available options
    }
  | ReportChatResultTextRequired -- ^ The user must add additional text details to the report
    { ReportChatResult -> Maybe ByteString
option_id   :: Maybe BS.ByteString -- ^ Option identifier for the next reportChat request
    , ReportChatResult -> Maybe Bool
is_optional :: Maybe Bool          -- ^ True, if the user can skip text adding
    }
  | ReportChatResultMessagesRequired -- ^ The user must choose messages to report and repeat the reportChat request with the chosen messages
  deriving (ReportChatResult -> ReportChatResult -> Bool
(ReportChatResult -> ReportChatResult -> Bool)
-> (ReportChatResult -> ReportChatResult -> Bool)
-> Eq ReportChatResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReportChatResult -> ReportChatResult -> Bool
== :: ReportChatResult -> ReportChatResult -> Bool
$c/= :: ReportChatResult -> ReportChatResult -> Bool
/= :: ReportChatResult -> ReportChatResult -> Bool
Eq, Int -> ReportChatResult -> ShowS
[ReportChatResult] -> ShowS
ReportChatResult -> String
(Int -> ReportChatResult -> ShowS)
-> (ReportChatResult -> String)
-> ([ReportChatResult] -> ShowS)
-> Show ReportChatResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReportChatResult -> ShowS
showsPrec :: Int -> ReportChatResult -> ShowS
$cshow :: ReportChatResult -> String
show :: ReportChatResult -> String
$cshowList :: [ReportChatResult] -> ShowS
showList :: [ReportChatResult] -> ShowS
Show)

instance I.ShortShow ReportChatResult where
  shortShow :: ReportChatResult -> String
shortShow ReportChatResult
ReportChatResultOk
      = String
"ReportChatResultOk"
  shortShow ReportChatResultOptionRequired
    { title :: ReportChatResult -> Maybe Text
title   = Maybe Text
title_
    , options :: ReportChatResult -> Maybe [ReportOption]
options = Maybe [ReportOption]
options_
    }
      = String
"ReportChatResultOptionRequired"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"title"   String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
        , String
"options" String -> Maybe [ReportOption] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [ReportOption]
options_
        ]
  shortShow ReportChatResultTextRequired
    { option_id :: ReportChatResult -> Maybe ByteString
option_id   = Maybe ByteString
option_id_
    , is_optional :: ReportChatResult -> Maybe Bool
is_optional = Maybe Bool
is_optional_
    }
      = String
"ReportChatResultTextRequired"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"option_id"   String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
option_id_
        , String
"is_optional" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_optional_
        ]
  shortShow ReportChatResult
ReportChatResultMessagesRequired
      = String
"ReportChatResultMessagesRequired"

instance AT.FromJSON ReportChatResult where
  parseJSON :: Value -> Parser ReportChatResult
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
"reportChatResultOk"               -> ReportChatResult -> Parser ReportChatResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReportChatResult
ReportChatResultOk
      String
"reportChatResultOptionRequired"   -> Value -> Parser ReportChatResult
parseReportChatResultOptionRequired Value
v
      String
"reportChatResultTextRequired"     -> Value -> Parser ReportChatResult
parseReportChatResultTextRequired Value
v
      String
"reportChatResultMessagesRequired" -> ReportChatResult -> Parser ReportChatResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReportChatResult
ReportChatResultMessagesRequired
      String
_                                  -> Parser ReportChatResult
forall a. Monoid a => a
mempty
    
    where
      parseReportChatResultOptionRequired :: A.Value -> AT.Parser ReportChatResult
      parseReportChatResultOptionRequired :: Value -> Parser ReportChatResult
parseReportChatResultOptionRequired = String
-> (Object -> Parser ReportChatResult)
-> Value
-> Parser ReportChatResult
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReportChatResultOptionRequired" ((Object -> Parser ReportChatResult)
 -> Value -> Parser ReportChatResult)
-> (Object -> Parser ReportChatResult)
-> Value
-> Parser ReportChatResult
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
title_   <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"title"
        Maybe [ReportOption]
options_ <- Object
o Object -> Key -> Parser (Maybe [ReportOption])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"options"
        ReportChatResult -> Parser ReportChatResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReportChatResult -> Parser ReportChatResult)
-> ReportChatResult -> Parser ReportChatResult
forall a b. (a -> b) -> a -> b
$ ReportChatResultOptionRequired
          { title :: Maybe Text
title   = Maybe Text
title_
          , options :: Maybe [ReportOption]
options = Maybe [ReportOption]
options_
          }
      parseReportChatResultTextRequired :: A.Value -> AT.Parser ReportChatResult
      parseReportChatResultTextRequired :: Value -> Parser ReportChatResult
parseReportChatResultTextRequired = String
-> (Object -> Parser ReportChatResult)
-> Value
-> Parser ReportChatResult
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReportChatResultTextRequired" ((Object -> Parser ReportChatResult)
 -> Value -> Parser ReportChatResult)
-> (Object -> Parser ReportChatResult)
-> Value
-> Parser ReportChatResult
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe ByteString
option_id_   <- (String -> ByteString) -> Maybe String -> Maybe ByteString
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> ByteString
I.readBytes (Maybe String -> Maybe ByteString)
-> Parser (Maybe String) -> Parser (Maybe ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"option_id"
        Maybe Bool
is_optional_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"is_optional"
        ReportChatResult -> Parser ReportChatResult
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReportChatResult -> Parser ReportChatResult)
-> ReportChatResult -> Parser ReportChatResult
forall a b. (a -> b) -> a -> b
$ ReportChatResultTextRequired
          { option_id :: Maybe ByteString
option_id   = Maybe ByteString
option_id_
          , is_optional :: Maybe Bool
is_optional = Maybe Bool
is_optional_
          }
  parseJSON Value
_ = Parser ReportChatResult
forall a. Monoid a => a
mempty