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

export default class X509_Remove extends Command {
  constructor(client: Client) {
    super(client);
    this.name = 'remove';
    this.aliases = ['rm', 'delete', 'del', 'unlink', 'disconnect'];
    this.description = 'Removes a currently connected X.509 certificate from your account.';
    this.usage = `${this.client.config.prefix}x509 ${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?.x509) return this.error(ctx.message.channel, 'There are no X.509 certificates connected to your account.');
    await profile.updateOne({ $unset: { x509: '' } });
    this.success(ctx.message.channel, 'Unlinked X.509 certificate from your account.');
  }
}
