-- | Provides data pertaining to Phone number patterns of different
-- countries & territories

module PhoneNumberMetadata
where

import  System.IO.Unsafe (unsafePerformIO)

data PhoneNumberMetadata   =  PhoneNumberMetadata {
  territories :: [Territory]
} deriving (Show, Read)


type NumberPattern = String
type PhoneNumber   = String
type SourceUrl     = String

data Territory     =  Territory {
  abbreviation                           :: String,
  countryCode                            :: String,
  mainCountryForCode                     :: Maybe Bool,
  leadingDigits                          :: Maybe String,
  preferredInternationalPrefix           :: Maybe String,
  internationalPrefix                    :: Maybe String,
  nationalPrefix                         :: Maybe String,
  nationalPrefixForParsing               :: Maybe String,
  nationalPrefixTransformRule            :: Maybe String,
  preferredExtensionPrefix               :: Maybe String,
  nationalPrefixFormattingRule           :: Maybe String,
  nationalPrefixOptionalWhenFormatting   :: Maybe Bool,
  leadingZeroPossible                    :: Maybe Bool,
  carrierCodeFormattingRule              :: Maybe String,
  mobileNumberPortableRegion             :: Maybe Bool,

  references                             :: [SourceUrl],
  availableFormats                       :: Maybe [NumberFormat],
  generalDescription                     :: Maybe PhoneNumberPatterns,
  noInternationalDialling                :: Maybe PhoneNumberPatterns,
  areaCodeOptional                       :: Maybe PhoneNumberPatterns,
  fixedLine                              :: Maybe PhoneNumberPatterns,
  mobile                                 :: Maybe PhoneNumberPatterns,
  pager                                  :: Maybe PhoneNumberPatterns,
  tollFree                               :: Maybe PhoneNumberPatterns,
  premiumRate                            :: Maybe PhoneNumberPatterns,
  sharedCost                             :: Maybe PhoneNumberPatterns,
  personalNumber                         :: Maybe PhoneNumberPatterns,
  voip                                   :: Maybe PhoneNumberPatterns,
  uan                                    :: Maybe PhoneNumberPatterns,
  voicemail                              :: Maybe PhoneNumberPatterns
} deriving (Show, Read)

data NumberFormat        = NumberFormat {
  nfNationalPrefixFormattingRule         :: Maybe String,
  nfNationalPrefixOptionalWhenFormatting :: Maybe Bool,
  nfCarrierCodeFormattingRule            :: Maybe String,
  nfPattern                              :: String,
  nfLeadingZeroPossible                  :: Maybe Bool,
  nfLeadingDigits                        :: Maybe [String],
  nfFormat                               :: String,
  nfInternationalFormat                  :: Maybe [String]
} deriving (Show, Read)

data PhoneNumberPatterns = PhoneNumberPatterns
  { nationalNumberPattern                :: Maybe NumberPattern
  , possibleNumberPattern                :: Maybe NumberPattern
  , exampleNumber                        :: Maybe PhoneNumber
  } deriving (Read, Show)

phoneNumberMetadata:: PhoneNumberMetadata
phoneNumberMetadata   =
  read $ unsafePerformIO $
  readFile "config/phoneNumberMetadata.hs" :: PhoneNumberMetadata