import { api } from 'boot/axios'

async function getTariffs () {
  return (await api.get('/payment/plan'))?.data.data
}

async function getTariffDiscount () {
  return (await api.get('payment/plan/discount'))?.data.data
}

async function calcUpgradeTariff (plan_id: number, period: number) {
  return (await api.get('/payment/plan/upgrade/calc', { params: { plan_id, period } }))?.data.data
}

async function urlUpgradeTariff (plan_id: number, period: number) {
  return (await api.post('/payment/plan/upgrade', { plan_id, period }))?.data.data.url
}

async function calcChangeTariff (plan_id: number) {
  return (await api.get('/payment/plan/change/calc', { params: { plan_id } }))?.data.data
}

async function changeTariff (plan_id: number) {
  return (await api.post('/payment/plan/change', { plan_id }))?.data.data
}

async function calcRenewTariff (plan_id: number, period: number) {
  return (await api.get('/payment/plan/renew/calc', { params: { plan_id, period } }))?.data.data
}

async function urlRenewTariff (plan_id: number, period: number) {
  return (await api.post('/payment/plan/renew', { plan_id, period }))?.data.data.url
}

async function sendPromocode (promocode: string) {
  return  (await api.post('/payment/plan/promocode', { promocode }))?.data.success
}

export {
  getTariffs,
  getTariffDiscount,
  calcUpgradeTariff,
  urlUpgradeTariff,
  calcChangeTariff,
  changeTariff,
  calcRenewTariff,
  urlRenewTariff,
  sendPromocode
}
