const {
    UserModel,
    PromocodeModel
} = global.config
const {
    generateVoucher
} = global.utils

module.exports = async (ctx) => {
    let user = await UserModel.findByPk(ctx.from.id)
    if(user.status != 'admin') return await ctx.reply(`Admin Only.`)
    ctx.args = ctx.update.message.text.split(' ')
    if (!ctx.args[1] || !ctx.args[2] || !ctx.args[3]) return ctx.reply(`/createpromo [activations] [money] [code]`)
    let promocode = await PromocodeModel.findOne({
        where: {
          code: ctx.args[3]
        }
      })
    if(promocode === null){
    await PromocodeModel.create({
        code: ctx.args[3],
        activations: ctx.args[1],
        money: ctx.args[2]
    })
    let voucherImage = await generateVoucher(ctx.args[3], ctx.args[1], ctx.args[2])
    console.log(voucherImage)
    return await ctx.sendPhoto({source: voucherImage, caption: `Создан промокод ${ctx.args[3]}` })
}
}