module TD.Data.CallProblem
  (CallProblem(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

-- | Describes the exact type of problem with a call
data CallProblem
  = CallProblemEcho -- ^ The user heard their own voice
  | CallProblemNoise -- ^ The user heard background noise
  | CallProblemInterruptions -- ^ The other side kept disappearing
  | CallProblemDistortedSpeech -- ^ The speech was distorted
  | CallProblemSilentLocal -- ^ The user couldn't hear the other side
  | CallProblemSilentRemote -- ^ The other side couldn't hear the user
  | CallProblemDropped -- ^ The call ended unexpectedly
  | CallProblemDistortedVideo -- ^ The video was distorted
  | CallProblemPixelatedVideo -- ^ The video was pixelated
  deriving (CallProblem -> CallProblem -> Bool
(CallProblem -> CallProblem -> Bool)
-> (CallProblem -> CallProblem -> Bool) -> Eq CallProblem
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CallProblem -> CallProblem -> Bool
== :: CallProblem -> CallProblem -> Bool
$c/= :: CallProblem -> CallProblem -> Bool
/= :: CallProblem -> CallProblem -> Bool
Eq, Int -> CallProblem -> ShowS
[CallProblem] -> ShowS
CallProblem -> String
(Int -> CallProblem -> ShowS)
-> (CallProblem -> String)
-> ([CallProblem] -> ShowS)
-> Show CallProblem
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CallProblem -> ShowS
showsPrec :: Int -> CallProblem -> ShowS
$cshow :: CallProblem -> String
show :: CallProblem -> String
$cshowList :: [CallProblem] -> ShowS
showList :: [CallProblem] -> ShowS
Show)

instance I.ShortShow CallProblem where
  shortShow :: CallProblem -> String
shortShow CallProblem
CallProblemEcho
      = String
"CallProblemEcho"
  shortShow CallProblem
CallProblemNoise
      = String
"CallProblemNoise"
  shortShow CallProblem
CallProblemInterruptions
      = String
"CallProblemInterruptions"
  shortShow CallProblem
CallProblemDistortedSpeech
      = String
"CallProblemDistortedSpeech"
  shortShow CallProblem
CallProblemSilentLocal
      = String
"CallProblemSilentLocal"
  shortShow CallProblem
CallProblemSilentRemote
      = String
"CallProblemSilentRemote"
  shortShow CallProblem
CallProblemDropped
      = String
"CallProblemDropped"
  shortShow CallProblem
CallProblemDistortedVideo
      = String
"CallProblemDistortedVideo"
  shortShow CallProblem
CallProblemPixelatedVideo
      = String
"CallProblemPixelatedVideo"

instance AT.FromJSON CallProblem where
  parseJSON :: Value -> Parser CallProblem
parseJSON (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
"callProblemEcho"            -> CallProblem -> Parser CallProblem
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CallProblem
CallProblemEcho
      String
"callProblemNoise"           -> CallProblem -> Parser CallProblem
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CallProblem
CallProblemNoise
      String
"callProblemInterruptions"   -> CallProblem -> Parser CallProblem
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CallProblem
CallProblemInterruptions
      String
"callProblemDistortedSpeech" -> CallProblem -> Parser CallProblem
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CallProblem
CallProblemDistortedSpeech
      String
"callProblemSilentLocal"     -> CallProblem -> Parser CallProblem
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CallProblem
CallProblemSilentLocal
      String
"callProblemSilentRemote"    -> CallProblem -> Parser CallProblem
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CallProblem
CallProblemSilentRemote
      String
"callProblemDropped"         -> CallProblem -> Parser CallProblem
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CallProblem
CallProblemDropped
      String
"callProblemDistortedVideo"  -> CallProblem -> Parser CallProblem
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CallProblem
CallProblemDistortedVideo
      String
"callProblemPixelatedVideo"  -> CallProblem -> Parser CallProblem
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CallProblem
CallProblemPixelatedVideo
      String
_                            -> Parser CallProblem
forall a. Monoid a => a
mempty
    
  parseJSON Value
_ = Parser CallProblem
forall a. Monoid a => a
mempty

instance AT.ToJSON CallProblem where
  toJSON :: CallProblem -> Value
toJSON CallProblem
CallProblemEcho
      = [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
"callProblemEcho"
        ]
  toJSON CallProblem
CallProblemNoise
      = [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
"callProblemNoise"
        ]
  toJSON CallProblem
CallProblemInterruptions
      = [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
"callProblemInterruptions"
        ]
  toJSON CallProblem
CallProblemDistortedSpeech
      = [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
"callProblemDistortedSpeech"
        ]
  toJSON CallProblem
CallProblemSilentLocal
      = [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
"callProblemSilentLocal"
        ]
  toJSON CallProblem
CallProblemSilentRemote
      = [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
"callProblemSilentRemote"
        ]
  toJSON CallProblem
CallProblemDropped
      = [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
"callProblemDropped"
        ]
  toJSON CallProblem
CallProblemDistortedVideo
      = [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
"callProblemDistortedVideo"
        ]
  toJSON CallProblem
CallProblemPixelatedVideo
      = [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
"callProblemPixelatedVideo"
        ]