import { Message } from 'eris';
import { Command, Client } 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 x509 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(message: Message) {
    const profile = await this.client.db.Member.findOne({ userID: message.author.id });
    if (!profile?.x509) return this.error(message.channel, 'There are no x509 certificates connected to your account.');
    await profile.updateOne({ $unset: { x509: '' } });
    this.success(message.channel, 'Unlinked x509 certificate from your account.');
  }
}
