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

export default class DelMerchant extends Command {
  constructor(client: Client) {
    super(client);
    this.name = 'delmerchant';
    this.description = 'Deletes a merchant.';
    this.usage = `${this.client.config.prefix}delmerchant <merchant id>`;
    this.aliases = ['dm'];
    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]));
    const merchant = await this.client.db.mongo.Merchant.findOne({ key: ctx.args[0] });
    if (!merchant) return this.error(ctx.message.channel, 'Merchant specified does not exist.');
    return this.success(ctx.message.channel, `Deleted merchant \`${merchant._id}\`.`);
  }
}
