import { Message } from 'eris';
import { Client, 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(message: Message, args: string[]) {
    try {
      if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
      const merchant = await this.client.db.Merchant.findOne({ key: args[0] });
      if (!merchant) return this.error(message.channel, 'Merchant specified does not exist.');
      return this.success(message.channel, `Deleted merchant \`${merchant._id}\`.`);
    } catch (err) {
      return this.client.util.handleError(err, message, this);
    }
  }
}
