const landSet = require('./i18n-lands.js')

module.exports = {
  validate_phone ({ phone } = {}) {
    try {
      let [fullphone, itc, callnumber] = /^\+(\d{1,3})-(\d{7,11})$/.exec(phone)
      switch (itc) {
        case landSet.CN.itc:
          return new RegExp(landSet.CN.reCallnumber).test(callnumber)
        case landSet.JP.itc:
          return new RegExp(landSet.JP.reCallnumber).test(callnumber)
        case landSet.SG.itc:
          return new RegExp(landSet.SG.reCallnumber).test(callnumber)
        case landSet.US.itc:
          return new RegExp(landSet.US.reCallnumber).test(callnumber)
        default:
          return true
      }
    } catch (error) {
      return false
    }
  },
}
