import * as Knex from "knex"
import { RPCExporter } from "rpclibrary";
import { RaidManagerIfc, RaidManagerFeatureIfc } from "../Components/Raid/RPCInterface";
import { LoginManagerIfc, CharacterManagerIfc, LoginManagerFeatureIfc, CharacterManagerFeatureIfc } from "../Components/User/RPCInterface";


export declare type NotificationSeverity = 'Info' | 'Important' | 'Error';

export type AdminConf = { 
    httpPort: number,
    dbConf:Knex.Config, 
    eventBusConf: { [topic in string]: NotificationSeverity}
}

export type TableDefiniton = {
    name: string, 
    tableBuilder: (table: Knex.CreateTableBuilder) => void
}

export type Rank =             "ADMIN" | "Guildmaster" | "Officer" | "Classleader" | "Raider" | "Trial" | "Social" | "Guest"
export const _Rank : Rank[] = ["ADMIN" , "Guildmaster" , "Officer" , "Classleader" , "Raider" , "Trial" , "Social" , "Guest"]
export type Class =              "Warrior" | "Rogue" | "Hunter" | "Mage" | "Warlock" | "Priest" | "Shaman" | "Paladin" | "Druid"
export const _Class : Class[] = ["Warrior" , "Rogue" , "Hunter" , "Mage" , "Warlock" , "Priest" , "Shaman" , "Paladin" , "Druid"]

export type AnyRPCExporter = RPCExporter<any,any>

export type RPCPermission = {
    name: string
} & {
    [rank in Rank] : boolean
}

export type User = {
    id?: number
    name: string
    pwhash: string
    rank: Rank
    email?: string
    locked: boolean
}

export type Raid = {
    id?: number
    title: string
    description: string
    start: string
    minrank: Rank
}

export type Signup = {
    raid_id: number
    user_id: number
}

export type Character = {
    id? : number
    name : string
    specid : number
    userid : number
}

export type Token = {
    value: string
    user_id: number
    created: number
}

export type Auth = {port: number, user: User, token: Token}

export type FrontcraftIfc = RaidManagerIfc
                          & LoginManagerIfc
                          & CharacterManagerIfc

export type FrontcraftFeatureIfc = RaidManagerFeatureIfc 
                                 & LoginManagerFeatureIfc
                                 & CharacterManagerFeatureIfc

export type Spec = {
    id?: number,
    class: Class,
    name: string
}

export type SomeOf<T> = {
    [K in keyof T]? : T[K]
}