module TD.Data.LanguagePackStringValue
  (LanguagePackStringValue(..)) 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

-- | Represents the value of a string in a language pack
data LanguagePackStringValue
  = LanguagePackStringValueOrdinary -- ^ An ordinary language pack string
    { LanguagePackStringValue -> Maybe Text
value :: Maybe T.Text -- ^ String value
    }
  | LanguagePackStringValuePluralized -- ^ A language pack string which has different forms based on the number of some object it mentions. See https://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html for more information
    { LanguagePackStringValue -> Maybe Text
zero_value  :: Maybe T.Text -- ^ Value for zero objects
    , LanguagePackStringValue -> Maybe Text
one_value   :: Maybe T.Text -- ^ Value for one object
    , LanguagePackStringValue -> Maybe Text
two_value   :: Maybe T.Text -- ^ Value for two objects
    , LanguagePackStringValue -> Maybe Text
few_value   :: Maybe T.Text -- ^ Value for few objects
    , LanguagePackStringValue -> Maybe Text
many_value  :: Maybe T.Text -- ^ Value for many objects
    , LanguagePackStringValue -> Maybe Text
other_value :: Maybe T.Text -- ^ Default value
    }
  | LanguagePackStringValueDeleted -- ^ A deleted language pack string, the value must be taken from the built-in English language pack
  deriving (LanguagePackStringValue -> LanguagePackStringValue -> Bool
(LanguagePackStringValue -> LanguagePackStringValue -> Bool)
-> (LanguagePackStringValue -> LanguagePackStringValue -> Bool)
-> Eq LanguagePackStringValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LanguagePackStringValue -> LanguagePackStringValue -> Bool
== :: LanguagePackStringValue -> LanguagePackStringValue -> Bool
$c/= :: LanguagePackStringValue -> LanguagePackStringValue -> Bool
/= :: LanguagePackStringValue -> LanguagePackStringValue -> Bool
Eq, Int -> LanguagePackStringValue -> ShowS
[LanguagePackStringValue] -> ShowS
LanguagePackStringValue -> String
(Int -> LanguagePackStringValue -> ShowS)
-> (LanguagePackStringValue -> String)
-> ([LanguagePackStringValue] -> ShowS)
-> Show LanguagePackStringValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LanguagePackStringValue -> ShowS
showsPrec :: Int -> LanguagePackStringValue -> ShowS
$cshow :: LanguagePackStringValue -> String
show :: LanguagePackStringValue -> String
$cshowList :: [LanguagePackStringValue] -> ShowS
showList :: [LanguagePackStringValue] -> ShowS
Show)

instance I.ShortShow LanguagePackStringValue where
  shortShow :: LanguagePackStringValue -> String
shortShow LanguagePackStringValueOrdinary
    { value :: LanguagePackStringValue -> Maybe Text
value = Maybe Text
value_
    }
      = String
"LanguagePackStringValueOrdinary"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"value" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
value_
        ]
  shortShow LanguagePackStringValuePluralized
    { zero_value :: LanguagePackStringValue -> Maybe Text
zero_value  = Maybe Text
zero_value_
    , one_value :: LanguagePackStringValue -> Maybe Text
one_value   = Maybe Text
one_value_
    , two_value :: LanguagePackStringValue -> Maybe Text
two_value   = Maybe Text
two_value_
    , few_value :: LanguagePackStringValue -> Maybe Text
few_value   = Maybe Text
few_value_
    , many_value :: LanguagePackStringValue -> Maybe Text
many_value  = Maybe Text
many_value_
    , other_value :: LanguagePackStringValue -> Maybe Text
other_value = Maybe Text
other_value_
    }
      = String
"LanguagePackStringValuePluralized"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"zero_value"  String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
zero_value_
        , String
"one_value"   String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
one_value_
        , String
"two_value"   String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
two_value_
        , String
"few_value"   String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
few_value_
        , String
"many_value"  String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
many_value_
        , String
"other_value" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
other_value_
        ]
  shortShow LanguagePackStringValue
LanguagePackStringValueDeleted
      = String
"LanguagePackStringValueDeleted"

instance AT.FromJSON LanguagePackStringValue where
  parseJSON :: Value -> Parser LanguagePackStringValue
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
"languagePackStringValueOrdinary"   -> Value -> Parser LanguagePackStringValue
parseLanguagePackStringValueOrdinary Value
v
      String
"languagePackStringValuePluralized" -> Value -> Parser LanguagePackStringValue
parseLanguagePackStringValuePluralized Value
v
      String
"languagePackStringValueDeleted"    -> LanguagePackStringValue -> Parser LanguagePackStringValue
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LanguagePackStringValue
LanguagePackStringValueDeleted
      String
_                                   -> Parser LanguagePackStringValue
forall a. Monoid a => a
mempty
    
    where
      parseLanguagePackStringValueOrdinary :: A.Value -> AT.Parser LanguagePackStringValue
      parseLanguagePackStringValueOrdinary :: Value -> Parser LanguagePackStringValue
parseLanguagePackStringValueOrdinary = String
-> (Object -> Parser LanguagePackStringValue)
-> Value
-> Parser LanguagePackStringValue
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"LanguagePackStringValueOrdinary" ((Object -> Parser LanguagePackStringValue)
 -> Value -> Parser LanguagePackStringValue)
-> (Object -> Parser LanguagePackStringValue)
-> Value
-> Parser LanguagePackStringValue
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
value_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"value"
        LanguagePackStringValue -> Parser LanguagePackStringValue
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LanguagePackStringValue -> Parser LanguagePackStringValue)
-> LanguagePackStringValue -> Parser LanguagePackStringValue
forall a b. (a -> b) -> a -> b
$ LanguagePackStringValueOrdinary
          { value :: Maybe Text
value = Maybe Text
value_
          }
      parseLanguagePackStringValuePluralized :: A.Value -> AT.Parser LanguagePackStringValue
      parseLanguagePackStringValuePluralized :: Value -> Parser LanguagePackStringValue
parseLanguagePackStringValuePluralized = String
-> (Object -> Parser LanguagePackStringValue)
-> Value
-> Parser LanguagePackStringValue
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"LanguagePackStringValuePluralized" ((Object -> Parser LanguagePackStringValue)
 -> Value -> Parser LanguagePackStringValue)
-> (Object -> Parser LanguagePackStringValue)
-> Value
-> Parser LanguagePackStringValue
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
zero_value_  <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"zero_value"
        Maybe Text
one_value_   <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"one_value"
        Maybe Text
two_value_   <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"two_value"
        Maybe Text
few_value_   <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"few_value"
        Maybe Text
many_value_  <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"many_value"
        Maybe Text
other_value_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"other_value"
        LanguagePackStringValue -> Parser LanguagePackStringValue
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LanguagePackStringValue -> Parser LanguagePackStringValue)
-> LanguagePackStringValue -> Parser LanguagePackStringValue
forall a b. (a -> b) -> a -> b
$ LanguagePackStringValuePluralized
          { zero_value :: Maybe Text
zero_value  = Maybe Text
zero_value_
          , one_value :: Maybe Text
one_value   = Maybe Text
one_value_
          , two_value :: Maybe Text
two_value   = Maybe Text
two_value_
          , few_value :: Maybe Text
few_value   = Maybe Text
few_value_
          , many_value :: Maybe Text
many_value  = Maybe Text
many_value_
          , other_value :: Maybe Text
other_value = Maybe Text
other_value_
          }
  parseJSON Value
_ = Parser LanguagePackStringValue
forall a. Monoid a => a
mempty

instance AT.ToJSON LanguagePackStringValue where
  toJSON :: LanguagePackStringValue -> Value
toJSON LanguagePackStringValueOrdinary
    { value :: LanguagePackStringValue -> Maybe Text
value = Maybe Text
value_
    }
      = [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
"languagePackStringValueOrdinary"
        , Key
"value" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
value_
        ]
  toJSON LanguagePackStringValuePluralized
    { zero_value :: LanguagePackStringValue -> Maybe Text
zero_value  = Maybe Text
zero_value_
    , one_value :: LanguagePackStringValue -> Maybe Text
one_value   = Maybe Text
one_value_
    , two_value :: LanguagePackStringValue -> Maybe Text
two_value   = Maybe Text
two_value_
    , few_value :: LanguagePackStringValue -> Maybe Text
few_value   = Maybe Text
few_value_
    , many_value :: LanguagePackStringValue -> Maybe Text
many_value  = Maybe Text
many_value_
    , other_value :: LanguagePackStringValue -> Maybe Text
other_value = Maybe Text
other_value_
    }
      = [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
"languagePackStringValuePluralized"
        , Key
"zero_value"  Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
zero_value_
        , Key
"one_value"   Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
one_value_
        , Key
"two_value"   Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
two_value_
        , Key
"few_value"   Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
few_value_
        , Key
"many_value"  Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
many_value_
        , Key
"other_value" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
other_value_
        ]
  toJSON LanguagePackStringValue
LanguagePackStringValueDeleted
      = [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
"languagePackStringValueDeleted"
        ]