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

module Faker.Address where

import Data.Text (Text)
import Faker (Fake, FakeT(..), FakerSettings(..), getLocale)
import Faker.Internal (cachedRandomUnresolvedVec, cachedRandomVec, cachedRegex, RegexFakeValue(..))
import Faker.Provider.Address
import Faker.TH
import Control.Monad.Catch
import Control.Monad.IO.Class

country :: Fake Text
country :: Fake Text
country = (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake (Text
-> Text
-> (FakerSettings -> IO (Vector Text))
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"address" Text
"country" FakerSettings -> IO (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
countryProvider)

$(generateFakeField "address" "cityPrefix")

citySuffix :: Fake Text
citySuffix :: Fake Text
citySuffix = (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake (Text
-> Text
-> (FakerSettings -> IO (Vector Text))
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"address" Text
"citySuffix" FakerSettings -> IO (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
citySuffixProvider)

countryCode :: Fake Text
countryCode :: Fake Text
countryCode = (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake (Text
-> Text
-> (FakerSettings -> IO (Vector Text))
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"address" Text
"countryCode" FakerSettings -> IO (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
countryCodeProvider)

countryCodeLong :: Fake Text
countryCodeLong :: Fake Text
countryCodeLong =
  (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake (Text
-> Text
-> (FakerSettings -> IO (Vector Text))
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"address" Text
"countryCodeLong" FakerSettings -> IO (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
countryCodeLongProvider)

buildingNumber :: Fake Text
buildingNumber :: Fake Text
buildingNumber =
  (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake
    (Text
-> Text
-> (FakerSettings -> IO (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> IO Text)
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> m Text)
-> FakerSettings
-> m Text
cachedRandomUnresolvedVec
       Text
"address"
       Text
"buildingNumber"
       FakerSettings -> IO (Unresolved (Vector Text))
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Unresolved (Vector Text))
buildingNumberProvider
       FakerSettings -> Text -> IO Text
forall (m :: * -> *).
(MonadIO m, MonadThrow m) =>
FakerSettings -> Text -> m Text
resolveAddressText)

communityPrefix :: Fake Text
communityPrefix :: Fake Text
communityPrefix =
  (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake (Text
-> Text
-> (FakerSettings -> IO (Vector Text))
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"address" Text
"communityPrefix" FakerSettings -> IO (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
communityPrefixProvider)

communitySuffix :: Fake Text
communitySuffix :: Fake Text
communitySuffix =
  (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake (Text
-> Text
-> (FakerSettings -> IO (Vector Text))
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"address" Text
"communitySuffix" FakerSettings -> IO (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
communitySuffixProvider)

$(generateFakeFieldUnresolved "address" "community")

streetSuffix :: Fake Text
streetSuffix :: Fake Text
streetSuffix =
  (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake (Text
-> Text
-> (FakerSettings -> IO (Vector Text))
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"address" Text
"streetSuffix" FakerSettings -> IO (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
streetSuffixProvider)

secondaryAddress :: Fake Text
secondaryAddress :: Fake Text
secondaryAddress =
  (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake
    (Text
-> Text
-> (FakerSettings -> IO (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> IO Text)
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> m Text)
-> FakerSettings
-> m Text
cachedRandomUnresolvedVec
       Text
"address"
       Text
"secondaryAddress"
       FakerSettings -> IO (Unresolved (Vector Text))
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Unresolved (Vector Text))
secondaryAddressProvider
       FakerSettings -> Text -> IO Text
forall (m :: * -> *).
(MonadIO m, MonadThrow m) =>
FakerSettings -> Text -> m Text
resolveAddressText)

postcode :: Fake Text
postcode :: Fake Text
postcode = (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake FakerSettings -> IO Text
forall (m :: * -> *).
(MonadIO m, MonadThrow m) =>
FakerSettings -> m Text
handlePostcode
  where
    handlePostcode :: (MonadIO m, MonadThrow m) => FakerSettings -> m Text
    handlePostcode :: FakerSettings -> m Text
handlePostcode FakerSettings
settings =
      case (FakerSettings -> Text
getLocale FakerSettings
settings) Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"vi", Text
"en-CA", Text
"fr-CA", Text
"en-GB", Text
"nl"] of
        Bool
True ->
          RegexFakeValue -> Text
unRegexFakeValue (RegexFakeValue -> Text) -> m RegexFakeValue -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
          (Text
-> Text
-> (FakerSettings -> m Regex)
-> FakerSettings
-> m RegexFakeValue
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m Regex)
-> FakerSettings
-> m RegexFakeValue
cachedRegex Text
"address" Text
"postcode" FakerSettings -> m Regex
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m Regex
postcodeRegexProvider 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
"address"
            Text
"postcode"
            FakerSettings -> m (Unresolved (Vector Text))
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Unresolved (Vector Text))
postcodeProvider
            FakerSettings -> Text -> m Text
forall (m :: * -> *).
(MonadIO m, MonadThrow m) =>
FakerSettings -> Text -> m Text
resolveAddressText
            FakerSettings
settings

state :: Fake Text
state :: Fake Text
state = (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake (Text
-> Text
-> (FakerSettings -> IO (Vector Text))
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"address" Text
"state" FakerSettings -> IO (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
stateProvider)

stateAbbr :: Fake Text
stateAbbr :: Fake Text
stateAbbr = (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake (Text
-> Text
-> (FakerSettings -> IO (Vector Text))
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"address" Text
"stateAbbr" FakerSettings -> IO (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
stateAbbrProvider)

timeZone :: Fake Text
timeZone :: Fake Text
timeZone = (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake (Text
-> Text
-> (FakerSettings -> IO (Vector Text))
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Vector Text))
-> FakerSettings
-> m Text
cachedRandomVec Text
"address" Text
"timeZone" FakerSettings -> IO (Vector Text)
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Vector Text)
timeZoneProvider)

city :: Fake Text
city :: Fake Text
city =
  (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake
    (Text
-> Text
-> (FakerSettings -> IO (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> IO Text)
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> m Text)
-> FakerSettings
-> m Text
cachedRandomUnresolvedVec Text
"address" Text
"city" FakerSettings -> IO (Unresolved (Vector Text))
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Unresolved (Vector Text))
cityProvider FakerSettings -> Text -> IO Text
forall (m :: * -> *).
(MonadIO m, MonadThrow m) =>
FakerSettings -> Text -> m Text
resolveAddressText)

streetName :: Fake Text
streetName :: Fake Text
streetName =
  (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake
    (Text
-> Text
-> (FakerSettings -> IO (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> IO Text)
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> m Text)
-> FakerSettings
-> m Text
cachedRandomUnresolvedVec
       Text
"address"
       Text
"streetName"
       FakerSettings -> IO (Unresolved (Vector Text))
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Unresolved (Vector Text))
streetNameProvider
       FakerSettings -> Text -> IO Text
forall (m :: * -> *).
(MonadIO m, MonadThrow m) =>
FakerSettings -> Text -> m Text
resolveAddressText)

streetAddress :: Fake Text
streetAddress :: Fake Text
streetAddress =
  (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake
    (Text
-> Text
-> (FakerSettings -> IO (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> IO Text)
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> m Text)
-> FakerSettings
-> m Text
cachedRandomUnresolvedVec
       Text
"address"
       Text
"streetAddress"
       FakerSettings -> IO (Unresolved (Vector Text))
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Unresolved (Vector Text))
streetAddressProvider
       FakerSettings -> Text -> IO Text
forall (m :: * -> *).
(MonadIO m, MonadThrow m) =>
FakerSettings -> Text -> m Text
resolveAddressText)

fullAddress :: Fake Text
fullAddress :: Fake Text
fullAddress =
  (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake
    (Text
-> Text
-> (FakerSettings -> IO (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> IO Text)
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> m Text)
-> FakerSettings
-> m Text
cachedRandomUnresolvedVec
       Text
"address"
       Text
"fullAddress"
       FakerSettings -> IO (Unresolved (Vector Text))
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Unresolved (Vector Text))
fullAddressProvider
       FakerSettings -> Text -> IO Text
forall (m :: * -> *).
(MonadIO m, MonadThrow m) =>
FakerSettings -> Text -> m Text
resolveAddressText)

-- | @since 0.6.0
mailBox :: Fake Text
mailBox :: Fake Text
mailBox =
  (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake
    (Text
-> Text
-> (FakerSettings -> IO (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> IO Text)
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> m Text)
-> FakerSettings
-> m Text
cachedRandomUnresolvedVec
       Text
"address"
       Text
"mail_box"
       FakerSettings -> IO (Unresolved (Vector Text))
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Unresolved (Vector Text))
mailBoxProvider
       FakerSettings -> Text -> IO Text
forall (m :: * -> *).
(MonadIO m, MonadThrow m) =>
FakerSettings -> Text -> m Text
resolveAddressText)

-- | @since 0.7.0
cityWithState :: Fake Text
cityWithState :: Fake Text
cityWithState =
  (FakerSettings -> IO Text) -> Fake Text
forall a. (FakerSettings -> IO a) -> Fake a
Fake
    (Text
-> Text
-> (FakerSettings -> IO (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> IO Text)
-> FakerSettings
-> IO Text
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
Text
-> Text
-> (FakerSettings -> m (Unresolved (Vector Text)))
-> (FakerSettings -> Text -> m Text)
-> FakerSettings
-> m Text
cachedRandomUnresolvedVec
       Text
"address"
       Text
"city_with_state"
       FakerSettings -> IO (Unresolved (Vector Text))
forall (m :: * -> *).
(MonadThrow m, MonadIO m) =>
FakerSettings -> m (Unresolved (Vector Text))
cityWithStateProvider
       FakerSettings -> Text -> IO Text
forall (m :: * -> *).
(MonadIO m, MonadThrow m) =>
FakerSettings -> Text -> m Text
resolveAddressText)