{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

module Faker.Provider.Name where

import Config
import Control.Monad.Catch
import Control.Monad.IO.Class
import Data.Monoid ((<>))
import Data.Text (Text)
import Data.Vector (Vector)
import Data.Yaml
import Faker
import Faker.Internal
import Faker.Provider.TH
import Language.Haskell.TH

parseName :: FromJSON a => FakerSettings -> Value -> Parser a
parseName :: FakerSettings -> Value -> Parser a
parseName FakerSettings
settings (Object Object
obj) = do
  Object
en <- Object
obj Object -> Text -> Parser Object
forall a. FromJSON a => Object -> Text -> Parser a
.: (FakerSettings -> Text
getLocale FakerSettings
settings)
  Object
faker <- Object
en Object -> Text -> Parser Object
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"faker"
  a
name <- Object
faker Object -> Text -> Parser a
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"name"
  a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
name
parseName FakerSettings
settings Value
val = String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser a) -> String -> Parser a
forall a b. (a -> b) -> a -> b
$ String
"expected Object, but got " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> (Value -> String
forall a. Show a => a -> String
show Value
val)

parseNameField ::
     (FromJSON a, Monoid a) => FakerSettings -> Text -> Value -> Parser a
parseNameField :: FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
txt Value
val = do
  Object
name <- FakerSettings -> Value -> Parser Object
forall a. FromJSON a => FakerSettings -> Value -> Parser a
parseName FakerSettings
settings Value
val
  a
field <- Object
name Object -> Text -> Parser (Maybe a)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
txt Parser (Maybe a) -> a -> Parser a
forall a. Parser (Maybe a) -> a -> Parser a
.!= a
forall a. Monoid a => a
mempty
  a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
field

parseNameFields ::
     (FromJSON a, Monoid a) => FakerSettings -> [Text] -> Value -> Parser a
parseNameFields :: FakerSettings -> [Text] -> Value -> Parser a
parseNameFields FakerSettings
settings [Text]
txts Value
val = do
  Value
name <- FakerSettings -> Value -> Parser Value
forall a. FromJSON a => FakerSettings -> Value -> Parser a
parseName FakerSettings
settings Value
val
  Value -> [Text] -> Parser a
forall a. FromJSON a => Value -> [Text] -> Parser a
helper Value
name [Text]
txts
  where
    helper :: (FromJSON a) => Value -> [Text] -> Parser a
    helper :: Value -> [Text] -> Parser a
helper Value
a [] = Value -> Parser a
forall a. FromJSON a => Value -> Parser a
parseJSON Value
a
    helper (Object Object
a) (Text
x:[Text]
xs) = do
      Value
field <- Object
a Object -> Text -> Parser Value
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
x
      Value -> [Text] -> Parser a
forall a. FromJSON a => Value -> [Text] -> Parser a
helper Value
field [Text]
xs
    helper Value
a (Text
x:[Text]
xs) = String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser a) -> String -> Parser a
forall a b. (a -> b) -> a -> b
$ String
"expect Object, but got " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> (Value -> String
forall a. Show a => a -> String
show Value
a)

parseUnresolvedNameField ::
     (FromJSON a, Monoid a)
  => FakerSettings
  -> Text
  -> Value
  -> Parser (Unresolved a)
parseUnresolvedNameField :: FakerSettings -> Text -> Value -> Parser (Unresolved a)
parseUnresolvedNameField FakerSettings
settings Text
txt Value
val = do
  Object
name <- FakerSettings -> Value -> Parser Object
forall a. FromJSON a => FakerSettings -> Value -> Parser a
parseName FakerSettings
settings Value
val
  a
field <- Object
name Object -> Text -> Parser (Maybe a)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? Text
txt Parser (Maybe a) -> a -> Parser a
forall a. Parser (Maybe a) -> a -> Parser a
.!= a
forall a. Monoid a => a
mempty
  Unresolved a -> Parser (Unresolved a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Unresolved a -> Parser (Unresolved a))
-> Unresolved a -> Parser (Unresolved a)
forall a b. (a -> b) -> a -> b
$ a -> Unresolved a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
field

$(genParser "name" "male_first_name")

$(genProvider "name" "male_first_name")

$(genParser "name" "female_first_name")

$(genProvider "name" "female_first_name")

$(genParser "name" "prefix")

$(genProvider "name" "prefix")

$(genParser "name" "suffix")

$(genProvider "name" "suffix")

$(genParser "name" "last_name")

$(genProvider "name" "last_name")

$(genParserUnresolved "name" "name")

$(genProviderUnresolved "name" "name")

$(genParserUnresolved "name" "name_with_middle")

$(genProviderUnresolved "name" "name_with_middle")

$(genParserUnresolved "name" "first_name")

$(genProviderUnresolved "name" "first_name")

-- For nl locale
$(genParser "name" "tussenvoegsel")

$(genProvider "name" "tussenvoegsel")

-- For en-nz locale
$(genParser "name" "surname")

$(genProvider "name" "surname")

resolveNameText :: (MonadThrow m, MonadIO m) => FakerSettings -> Text -> m Text
resolveNameText :: FakerSettings -> Text -> m Text
resolveNameText = (FakerSettings -> Text -> m Text)
-> FakerSettings -> Text -> m Text
forall (m :: * -> *).
(MonadIO m, MonadThrow m) =>
(FakerSettings -> Text -> m Text)
-> FakerSettings -> Text -> m Text
genericResolver' FakerSettings -> Text -> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> Text -> m Text
resolveNameField

resolveNameField :: (MonadThrow m, MonadIO m) => FakerSettings -> Text -> m Text
resolveNameField :: FakerSettings -> Text -> m Text
resolveNameField FakerSettings
settings field :: Text
field@Text
"female_first_name" =
  Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
nameFemaleFirstNameProvider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"male_first_name" =
  Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
nameMaleFirstNameProvider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"prefix" =
  Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
namePrefixProvider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"suffix" =
  Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
nameSuffixProvider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"first_name" =
  case (FakerSettings -> Text
getLocale FakerSettings
settings) Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"id"] of
    Bool
True -> do
      let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
          parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
          provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
      Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
"first_name2" FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
    Bool
False ->
      Text
-> Text
-> (FakerSettings -> m (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> m Text)
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> m Text)
-> FakerSettings
-> m Text
cachedRandomUnresolvedVec
        Text
"name"
        Text
field
        FakerSettings -> m (Unresolved (Vector Text))
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Unresolved (Vector Text))
nameFirstNameProvider
        FakerSettings -> Text -> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> Text -> m Text
resolveNameText
        FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"last_name" =
  Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
nameLastNameProvider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"tussenvoegsel" =
  Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
nameTussenvoegselProvider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"male_last_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"female_last_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"female_middle_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"male_middle_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"middle_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"male_prefix" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"female_prefix" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"nobility_title_prefix" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"nobility_title" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"malay_male_first_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"malay_female_first_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"chinese_male_first_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"chinese_male_last_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"chinese_female_first_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"male_english_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"female_english_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"woman_last_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"man_last_name" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"surname" =
  let parser :: (FromJSON a, Monoid a) => FakerSettings -> Value -> Parser a
      parser :: FakerSettings -> Value -> Parser a
parser FakerSettings
settings = FakerSettings -> Text -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Text -> Value -> Parser a
parseNameField FakerSettings
settings Text
field
      provider :: FakerSettings -> m a
provider FakerSettings
settings = FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
Name FakerSettings -> Value -> Parser a
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser a
parser
   in Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"name" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolveNameField FakerSettings
settings field :: Text
field@Text
"Name.surname" =
  FakerSettings -> Text -> m Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> Text -> m Text
resolveNameText FakerSettings
settings Text
"surname"
resolveNameField FakerSettings
settings Text
str = FakerException -> m Text
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (FakerException -> m Text) -> FakerException -> m Text
forall a b. (a -> b) -> a -> b
$ String -> Text -> FakerException
InvalidField String
"name" Text
str