import { Message } from 'eris';
import { Client, Command, RichEmbed } from '../class';

import X509_Upload from './x509_upload';
import X509_Remove from './x509_remove';

export default class X509 extends Command {
  constructor(client: Client) {
    super(client);
    this.name = 'x509';
    this.description = 'Uploads to or removes from your account an x509 certificate.';
    this.usage = `${this.client.config.prefix}${this.name}`;
    this.permissions = 0;
    this.guildOnly = true;
    this.enabled = true;
    this.subcmds = [X509_Upload, X509_Remove];
  }

  public async run(message: Message) {
    const profile = await this.client.db.Member.findOne({ userID: message.author.id });
    const embed = new RichEmbed()
      .setAuthor(`${message.author.username}#${message.author.discriminator}`, message.author.dynamicAvatarURL())
      .setTitle('x509 Connections')
      .setDescription(profile?.x509 ? 'An x509 certificate is currently connected to your account.' : 'There are no x509 certificates connected to your account')
      .setTimestamp();
    message.channel.createMessage({ embed });
  }
}
