import { Client, CmdContext, Command } from '../class';

export default class DeletePromoCode extends Command {
  constructor(client: Client) {
    super(client);
    this.name = 'delpromo';
    this.description = 'Deletes a promotional code for Stripe.';
    this.usage = `${this.client.config.prefix}delpromo <stripe PC API id>`;
    this.aliases = ['dp'];
    this.permissions = 6;
    this.guildOnly = true;
    this.enabled = true;
  }

  public async run(ctx: CmdContext) {
    if (!ctx.args[0]) return this.client.commands.get('help').run(new CmdContext(ctx.message, [this.name]));
    try {
      await this.client.stripe.promotionCodes.retrieve(ctx.args[0]);
      await this.client.db.mongo.Promo.deleteOne({ pID: ctx.args[0] }).lean().exec();
    } catch (err) {
      return this.error(ctx.message.channel, 'Promotional API ID doesn\'t exist.');
    }
  }
}
