const invoker = require('./invoker')

function CDRator (config, defaultContext) {
  this.send = invoker.send.bind(invoker, config, defaultContext)
}

CDRator.prototype.assignCampaign = async function (subscriptionId, campaignKey) {
  return this.send('SOAP_ASSIGN_CAMPAIGN', {
    subscriptionId: subscriptionId,
    campaignKey: campaignKey
  })
}

CDRator.prototype.checkUsernameAvailability = async function (username) {
  return this.send('SOAP_CHECK_USERNAME_AVAILABILITY', {
    username: username
  })
}

CDRator.prototype.createRechargeTicket = async function (billingGroupId, reference, ticketId) {
  return this.send('SOAP_CREATE_RECHARGE_TICKET', {
    'billingGroupId': billingGroupId,
    'reference': reference,
    'ticketId': ticketId,
    'ticketType': 'BASE'
  })
}

CDRator.prototype.deleteRechargeTicket = async function (billingGroupId) {
  return this.send('SOAP_DELETE_RECHARGE_TICKET', {
    'billingGroupId': billingGroupId
  })
}

CDRator.prototype.doAddressCheck = async function (personalId) {
  return this.send('SOAP_DO_ADDRESS_CHECK', {
    personalId: personalId
  })
}

CDRator.prototype.doCreditCheck = async function (personalId) {
  return this.send('SOAP_DO_CREDIT_CHECK', {
    personalId: personalId
  })
}

CDRator.prototype.getANumbers = async function (len, text) {
  return this.send('SOAP_GET_ANUMBERS', {
    groupId: '40',
    searchMethod: text ? 2 : 0,
    count: len,
    pattern: text || ''
  })
}

CDRator.prototype.getInvoicePdf = async function (invoiceId) {
  return this.send('SOAP_GET_INVOICE_PDF', {
    invoice: invoiceId
  })
}

CDRator.prototype.getRechargeTicket = async function (billingGroupId) {
  return this.send('SOAP_GET_RECHARGE_TICKET', {
    'billingGroupId': billingGroupId
  })
}

CDRator.prototype.reservePhoneNumber = async function (number, minutes) {
  return this.send('SOAP_RESERVE_PHONE_NUMBER', {
    phoneNumber: number,
    reserveTime: minutes
  })
}

CDRator.prototype.subscribeProductOptions = async function (subscriptionId, options) {
  return this.send('SOAP_SUBSCRIBE_PRODUCT_OPTIONS', {
    'subscriptionId': subscriptionId,
    'productOptions': options
  })
}

CDRator.prototype.unsubscribeProductOptions = async function (subscriptionId, options) {
  return this.send('SOAP_UNSUBSCRIBE_PRODUCT_OPTIONS', {
    'subscriptionId': subscriptionId,
    'productOptionIds': options
  })
}

CDRator.prototype.updateUser = async function (userValues) {
  return this.send('SOAP_UPDATE_USER', {
    user: userValues
  })
}

CDRator.prototype.validatePersonalIdForSignup = async function (personalId) {
  return this.send('SOAP_VALIDATE_PERSONAL_ID_FOR_SIGNUP', {
    'personalId': personalId
  })
}

CDRator.prototype.terminateSubscription = async function (subscriptionId, terminationRequest) {
  return this.send('SOAP_TERMINATE_SUBSCRIPTION', {
    'subscriptionId': subscriptionId,
    'terminationRequest': terminationRequest
  })
}

CDRator.prototype.blockSim = async function (icc, blockType) {
  return this.send('SOAP_BLOCK_SIMCARD', {
    'icc': icc,
    'blockType': blockType
  })
}

CDRator.prototype.payInvoiceUsingRechargeTicket = async function (invoiceId) {
  return this.send('SOAP_PAY_INVOICE_USING_RECHARGETICKET', {
    'invoiceId': invoiceId
  })
}

CDRator.prototype.createFullSubscription = async function (subscription) {
  return this.send('SOAP_CREATE_FULL_SUBSCRIPTION', subscription)
}

CDRator.prototype.reservePhoneNumber = async function (phoneNumber, reserveTime) {
  return this.send('SOAP_RESERVE_PHONE_NUMBER', {
    'phoneNumber': phoneNumber,
    'reserveTime': reserveTime
  })
}

CDRator.prototype.startSwTelcoMigration = async function (subscriptionId, portDate) {
  return this.send('START_SW_TELCO_MIGRATION', {
    'subscriptionId': subscriptionId,
    'portDate': portDate
  })
}

module.exports = function (config, defaultContext) {
  return new CDRator(config, defaultContext)
}
