import { Utils } from '@nativescript/core';
export class SupabaseRealtimeClient {
    get status() {
        switch (this.native.status) {
            case 0 /* NSCSupabaseRealtimeChannelStatus.Unsubscribed */:
                return 'UNSUBSCRIBED';
            case 1 /* NSCSupabaseRealtimeChannelStatus.Subscribing */:
                return 'SUBSCRIBING';
            case 2 /* NSCSupabaseRealtimeChannelStatus.Subscribed */:
                return 'SUBSCRIBED';
            case 3 /* NSCSupabaseRealtimeChannelStatus.Unsubscribing */:
                return 'UNSUBSCRIBING';
        }
    }
    static fromNative(value) {
        if (!value)
            return null;
        const ret = new SupabaseRealtimeClient();
        ret._native = value;
        return ret;
    }
    get native() {
        return this._native;
    }
    on(type, filter, callback) {
        if (type) {
            if (type === 'broadcast') {
                this.native.onBroadcast(filter.event, (message) => {
                    callback(Utils.dataDeserialize(message));
                });
            }
            else if (type === 'presence') {
                this.native.onPresenceChange(filter.event, (event) => {
                    callback(Utils.dataDeserialize(event));
                });
            }
            else if (type === 'postgres_changes' && filter && 'event' in filter && 'schema' in filter) {
                this.native.onPostgresChange(filter.event, filter.schema, filter.filter ?? null, filter.table ?? null, (payload) => {
                    callback(Utils.dataDeserialize(payload));
                });
            }
        }
        return this;
    }
    subscribe() {
        return new Promise((resolve, reject) => {
            this.native.subscribe(() => {
                resolve();
            });
        });
    }
    unsubscribe() {
        return new Promise((resolve, reject) => {
            this.native.unsubscribe(() => {
                resolve();
            });
        });
    }
}
//# sourceMappingURL=index.ios.js.map