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

export default class DelNote extends Command {
  constructor(client: Client) {
    super(client);
    this.name = 'delnote';
    this.description = 'Deletes a note.';
    this.usage = `${this.client.config.prefix}delnote <note id>`;
    this.permissions = 1;
    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 note = await this.client.db.mongo.Note.findOne({ _id: ctx.args[0] }).lean().exec().catch(() => {});
    if (!note) return this.error(ctx.message.channel, 'Could not locate that note.');
    await this.client.db.mongo.Note.deleteOne({ _id: note._id });
    return this.success(ctx.message.channel, `Note # \`${note._id}\` has been deleted.`);
  }
}
