import Eris from 'eris';
import { Client } from '.';

// eslint-disable-next-line no-shadow
export enum InteractionCommandOptionsType {
  SUB_COMMAND = 1,
  SUB_COMMAND_GROUP,
  STRING,
  INTEGER,
  BOOLEAN,
  USER,
  CHANNEL,
  ROLE,
  MENTIONABLE,
  NUMBER
}

export interface InteractionCommandOptionsChoice {
  name: string;
  value: string | number;
}

export interface InteractionCommandOptions {
  type: InteractionCommandOptionsType;
  name: string;
  description: string;
  required?: boolean;
  choices?: InteractionCommandOptionsChoice[];
  options?: [InteractionCommandOptionsChoice];
  channel_types?: [Eris.GuildChannelTypes];
  min_value?: number;
  max_value?: number;
  autocomplete?: boolean;
}

export default class InteractionCommand {
  public client: Client;

  public id: string;

  public name: string;

  public description: string;

  public permissions: number;

  public options?: [InteractionCommandOptions?];

  constructor(client: Client) {
    this.client = client;
    this.options = [];
  }

  public serializeData(): Eris.ChatInputApplicationCommandStructure {
    const commandOptions = [];
    for (const option of this.options) {
      commandOptions.push(option);
    }
    const serializedData = {
      name: this.name,
      description: this.description,
      type: (<1>1),
      options: commandOptions,
    };
    return serializedData;
  }

  public checkPermissions(member: Eris.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: Eris.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 run(interaction: Eris.CommandInteraction): Promise<any> { return Promise.resolve(); }

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