{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Faker.Provider.PhoneNumber where
import Config
import Control.Monad.Catch
import Control.Monad.IO.Class
import Data.Map.Strict (Map)
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
parsePhoneNumber :: FromJSON a => FakerSettings -> Value -> Parser a
parsePhoneNumber :: FakerSettings -> Value -> Parser a
parsePhoneNumber 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
phoneNumber <- Object
faker Object -> Text -> Parser a
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"phone_number"
a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
phoneNumber
parsePhoneNumber 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)
parsePhoneNumberField ::
(FromJSON a, Monoid a) => FakerSettings -> Text -> Value -> Parser a
parsePhoneNumberField :: FakerSettings -> Text -> Value -> Parser a
parsePhoneNumberField FakerSettings
settings Text
txt Value
val = do
Object
phoneNumber <- FakerSettings -> Value -> Parser Object
forall a. FromJSON a => FakerSettings -> Value -> Parser a
parsePhoneNumber FakerSettings
settings Value
val
a
field <- Object
phoneNumber 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
parsePhoneNumberFields ::
(FromJSON a, Monoid a) => FakerSettings -> [Text] -> Value -> Parser a
parsePhoneNumberFields :: FakerSettings -> [Text] -> Value -> Parser a
parsePhoneNumberFields FakerSettings
settings [Text]
txts Value
val = do
Value
phoneNumber <- FakerSettings -> Value -> Parser Value
forall a. FromJSON a => FakerSettings -> Value -> Parser a
parsePhoneNumber FakerSettings
settings Value
val
Value -> [Text] -> Parser a
forall a. FromJSON a => Value -> [Text] -> Parser a
helper Value
phoneNumber [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)
parseCellPhone :: FromJSON a => FakerSettings -> Value -> Parser a
parseCellPhone :: FakerSettings -> Value -> Parser a
parseCellPhone 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
phoneNumber <- Object
faker Object -> Text -> Parser a
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"cell_phone"
a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
phoneNumber
parseCellPhone 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)
parseCellPhoneField ::
(FromJSON a, Monoid a) => FakerSettings -> Text -> Value -> Parser a
parseCellPhoneField :: FakerSettings -> Text -> Value -> Parser a
parseCellPhoneField FakerSettings
settings Text
txt Value
val = do
Object
phoneNumber <- FakerSettings -> Value -> Parser Object
forall a. FromJSON a => FakerSettings -> Value -> Parser a
parsePhoneNumber FakerSettings
settings Value
val
a
field <- Object
phoneNumber 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
parseUnresolvedCellPhoneField ::
(FromJSON a, Monoid a)
=> FakerSettings
-> Text
-> Value
-> Parser (Unresolved a)
parseUnresolvedCellPhoneField :: FakerSettings -> Text -> Value -> Parser (Unresolved a)
parseUnresolvedCellPhoneField FakerSettings
settings Text
txt Value
val = do
Object
cellphone <- FakerSettings -> Value -> Parser Object
forall a. FromJSON a => FakerSettings -> Value -> Parser a
parseCellPhone FakerSettings
settings Value
val
a
field <- Object
cellphone 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
parseUnresolvedPhoneNumberField ::
(FromJSON a, Monoid a)
=> FakerSettings
-> Text
-> Value
-> Parser (Unresolved a)
parseUnresolvedPhoneNumberField :: FakerSettings -> Text -> Value -> Parser (Unresolved a)
parseUnresolvedPhoneNumberField FakerSettings
settings Text
txt Value
val = do
Object
phoneNumber <- FakerSettings -> Value -> Parser Object
forall a. FromJSON a => FakerSettings -> Value -> Parser a
parsePhoneNumber FakerSettings
settings Value
val
a
field <- Object
phoneNumber 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
$(genParserUnresolved "phoneNumber" "formats")
$(genProviderUnresolved "phoneNumber" "formats")
$(genParserUnresolved "cellPhone" "formats")
$(genParserUnresolved "cellPhone" "subscriber_number")
cellPhoneFormatProvider ::
(MonadThrow m, MonadIO m) => FakerSettings -> m (Unresolved (Vector Text))
cellPhoneFormatProvider :: FakerSettings -> m (Unresolved (Vector Text))
cellPhoneFormatProvider FakerSettings
settings =
FakerSettings
-> SourceData
-> (FakerSettings -> Value -> Parser (Unresolved (Vector Text)))
-> m (Unresolved (Vector Text))
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
PhoneNumber FakerSettings -> Value -> Parser (Unresolved (Vector Text))
forall a.
(FromJSON a, Monoid a) =>
FakerSettings -> Value -> Parser (Unresolved a)
parseCellPhoneFormatsUnresolved
parseCountryCode :: FromJSON a => FakerSettings -> Value -> Parser a
parseCountryCode :: FakerSettings -> Value -> Parser a
parseCountryCode 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
countryCode <- Object
faker Object -> Text -> Parser a
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"country_code"
a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
countryCode
parseCountryCode 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)
countryCodeProvider ::
(MonadThrow m, MonadIO m) => FakerSettings -> m (Vector Text)
countryCodeProvider :: FakerSettings -> m (Vector Text)
countryCodeProvider FakerSettings
settings = FakerSettings
-> SourceData
-> (FakerSettings -> Value -> Parser (Vector Text))
-> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData -> (FakerSettings -> Value -> Parser a) -> m a
fetchData FakerSettings
settings SourceData
PhoneNumber FakerSettings -> Value -> Parser (Vector Text)
forall a. FromJSON a => FakerSettings -> Value -> Parser a
parseCountryCode
resolvePhoneNumberText ::
(MonadIO m, MonadThrow m) => FakerSettings -> Text -> m Text
resolvePhoneNumberText :: FakerSettings -> Text -> m Text
resolvePhoneNumberText = (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
resolvePhoneNumberField
resolvePhoneNumberField ::
(MonadThrow m, MonadIO m) => FakerSettings -> Text -> m Text
resolvePhoneNumberField :: FakerSettings -> Text -> m Text
resolvePhoneNumberField FakerSettings
settings field :: Text
field@Text
"PhoneNumber.area_code" = 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
parsePhoneNumberField FakerSettings
settings Text
"area_code"
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
PhoneNumber 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
"phoneNumber" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolvePhoneNumberField FakerSettings
settings field :: Text
field@Text
"PhoneNumber.exchange_code" = 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
parsePhoneNumberField FakerSettings
settings Text
"exchange_code"
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
PhoneNumber 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
"phoneNumber" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolvePhoneNumberField FakerSettings
settings field :: Text
field@Text
"PhoneNumber.subscriber_number" = 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
parsePhoneNumberField FakerSettings
settings Text
"subscriber_number"
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
PhoneNumber 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
"phoneNumber" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolvePhoneNumberField FakerSettings
settings field :: Text
field@Text
"PhoneNumber.extension" = 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
parsePhoneNumberField FakerSettings
settings Text
"extension"
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
PhoneNumber 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
"phoneNumber" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolvePhoneNumberField FakerSettings
settings field :: Text
field@Text
"area_code" = 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
parsePhoneNumberField FakerSettings
settings Text
"area_code"
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
PhoneNumber 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
"phoneNumber" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolvePhoneNumberField FakerSettings
settings field :: Text
field@Text
"subscriber_number" = 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
parsePhoneNumberField FakerSettings
settings Text
"subscriber_number"
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
PhoneNumber 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
"phoneNumber" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *) a.
(MonadThrow m, MonadIO m, FromJSON a, Monoid a) =>
FakerSettings -> m a
provider FakerSettings
settings
resolvePhoneNumberField FakerSettings
settings field :: Text
field@Text
"country_code" = 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
parsePhoneNumberField FakerSettings
settings Text
field
provider :: FakerSettings -> m (Vector Text)
provider FakerSettings
settings = FakerSettings
-> SourceData
-> (FakerSettings -> Value -> Parser Text)
-> m (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings
-> SourceData
-> (FakerSettings -> Value -> Parser Text)
-> m (Vector Text)
fetchDataSingle FakerSettings
settings SourceData
PhoneNumber FakerSettings -> Value -> Parser Text
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
"phoneNumber" Text
field FakerSettings -> m (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
provider FakerSettings
settings
resolvePhoneNumberField 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
"phoneNumber" Text
str