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

export default class PGP_Remove extends Command {
  constructor(client: Client) {
    super(client);
    this.name = 'remove';
    this.aliases = ['rm', 'delete', 'del', 'unlink', 'disconnect'];
    this.description = 'Removes a currently connected PGP public key from your account.';
    this.usage = `${this.client.config.prefix}pgp ${this.name}`;
    this.permissions = 0;
    this.guildOnly = true;
    this.enabled = true;
  }

  public async run(ctx: CmdContext) {
    const profile = await this.client.db.mongo.Member.findOne({ userID: ctx.message.author.id });
    if (!profile?.pgp) return this.error(ctx.message.channel, 'There are no PGP public keys connected to your account.');
    await profile.updateOne({ $unset: { pgp: '' } });
    this.success(ctx.message.channel, 'Unlinked PGP public key from your account.');
  }
}
