import { Member, Message, TextableChannel } from 'eris';
import { Client, Collection } from '.';

export default class Command {
  public client: Client;

  /**
   * The name of the command
   */
  public name: string;
  /**
   * The description for the command.
   */

  public description: string;

  /**
   * Usage for the command.
   */
  public usage: string;
  /**
   * The aliases for the command.
   */

  public aliases: string[];

  /**
   * - **0:** Everyone
   * - **1:** Associates+
   * - **2:** Core Team+
   * - **3:** Moderators, Supervisor, & Board of Directors
   * - **4:** Technicians, Supervisor, & Board of Directors
   * - **5:** Moderators, Technicians, Supervisor, & Board of Directors
   * - **6:** Supervisor+
   * - **7:** Board of Directors
   */
  public permissions: number;

  /**
   * Determines if the command is only available in server.
   */
  public guildOnly: boolean;

  /**
   * Determines if the command is enabled or not.
   */

  public subcommands?: Collection<Command>;

  public subcmds?: any[];

  public enabled: boolean;

  public run(message: Message, args: string[]): Promise<any> { return Promise.resolve(); }

  constructor(client: Client) {
    this.client = client;

    this.aliases = [];

    this.subcommands = new Collection<Command>();

    this.subcmds = [];
  }

  get mainGuild() {
    return this.client.guilds.get(this.client.config.guildID);
  }

  public checkPermissions(member: Member): boolean {
    if (member.id === '278620217221971968' || member.id === '253600545972027394') return true;
    switch (this.permissions) {
      case 0:
        return true;
      case 1:
        return member.roles.some((r) => ['701481967149121627', '453689940140883988', '455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r));
      case 2:
        return member.roles.some((r) => ['453689940140883988', '455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r));
      case 3:
        return member.roles.some((r) => ['455972169449734144', '701454855952138300', '662163685439045632'].includes(r));
      case 4:
        return member.roles.some((r) => ['701454780828221450', '701454855952138300', '662163685439045632'].includes(r));
      case 5:
        return member.roles.some((r) => ['455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r));
      case 6:
        return member.roles.some((r) => ['701454855952138300', '662163685439045632'].includes(r));
      case 7:
        return member.roles.includes('662163685439045632');
      default:
        return false;
    }
  }

  public checkCustomPermissions(member: Member, permission: number): boolean {
    if (member.id === '278620217221971968' || member.id === '253600545972027394') return true;
    switch (permission) {
      case 0:
        return true;
      case 1:
        return member.roles.some((r) => ['701481967149121627', '453689940140883988', '455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r));
      case 2:
        return member.roles.some((r) => ['453689940140883988', '455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r));
      case 3:
        return member.roles.some((r) => ['455972169449734144', '701454855952138300', '662163685439045632'].includes(r));
      case 4:
        return member.roles.some((r) => ['701454780828221450', '701454855952138300', '662163685439045632'].includes(r));
      case 5:
        return member.roles.some((r) => ['455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r));
      case 6:
        return member.roles.some((r) => ['701454855952138300', '662163685439045632'].includes(r));
      case 7:
        return member.roles.includes('662163685439045632');
      default:
        return false;
    }
  }

  public error(channel: TextableChannel, text: string): Promise<Message> {
    return channel.createMessage(`***${this.client.util.emojis.ERROR} ${text}***`);
  }

  public success(channel: TextableChannel, text: string): Promise<Message> {
    return channel.createMessage(`***${this.client.util.emojis.SUCCESS} ${text}***`);
  }

  public loading(channel: TextableChannel, text: string): Promise<Message> {
    return channel.createMessage(`***${this.client.util.emojis.LOADING} ${text}***`);
  }
}
