import {App} from './App'
import {BaseAppDataMap, BaseEventMap} from './types'

type MyEventMap = BaseEventMap & {
    'wa.ready': {},
}

type MyAppDataMap = BaseAppDataMap & {
    waReady: boolean,
}

let appInstance: any = undefined
export const app = (): App<MyEventMap, MyAppDataMap> => {
    if ( !appInstance ) {
        appInstance = new App<MyEventMap, MyAppDataMap>()
        appInstance.event('wa.ready')
            .subscribe(() => appInstance.set('waReady', true))
    }

    return appInstance
}
