var _a, _b, _c;
import { Auth } from './auth';
import { SupabaseFunctionsClient } from './functions';
import { SupabaseStorageClient } from './storage';
import { SupabaseRealtimeClient } from './realtime';
import { PostgresFilterBuilder, SupabasePostgresClient, SupabasePostgresQueryBuilder } from './postgres';
function parseCount(count) {
    switch (count) {
        case 'exact':
            return org.nativescript.supabase.SupabaseClient.CountOption.exact;
        case 'planned':
            return org.nativescript.supabase.SupabaseClient.CountOption.planned;
        case 'estimated':
            return org.nativescript.supabase.SupabaseClient.CountOption.estimated;
        default:
            return null;
    }
}
const auth_ = Symbol('[[auth]]');
const functions_ = Symbol('[[functions]]');
const storage_ = Symbol('[[storage]]');
export class SupabaseClient {
    constructor() {
        this[_a] = new Auth(this);
        this[_b] = new SupabaseFunctionsClient(this);
        this[_c] = new SupabaseStorageClient(this);
    }
    static fromNative(native) {
        if (!native)
            return null;
        const ret = new SupabaseClient();
        ret.native = native;
        return ret;
    }
    get auth() {
        return this[auth_];
    }
    get functions() {
        return this[functions_];
    }
    get storage() {
        return this[storage_];
    }
    schema(schema) {
        return SupabasePostgresClient.fromNative(this.native.schema(schema));
    }
    from(relation) {
        return SupabasePostgresQueryBuilder.fromNative(this.native.from(relation));
    }
    channel(name) {
        return SupabaseRealtimeClient.fromNative(this.native.channel(name));
    }
    removeChannel(channel) {
        return new Promise((resolve, reject) => {
            this.native.removeChannel(channel.native);
            resolve();
        });
    }
    removeAllChannels() {
        return new Promise((resolve, reject) => {
            this.native.removeAllChannels();
            resolve();
        });
    }
    rpc(fn, args, options) {
        const ret = new PostgresFilterBuilder();
        if (args && options?.count) {
            const value = this.native.rpc(fn, JSON.stringify(args), parseCount(options.count));
            ret.native_ = value;
            return ret;
        }
        else if (args) {
            const value = this.native.rpc(fn, JSON.stringify(args), null);
            ret.native_ = value;
            return ret;
        }
        else if (options?.count) {
            const value = this.native.rpc(fn, null, parseCount(options.count));
            ret.native_ = value;
            return ret;
        }
        else {
            const value = this.native.rpc(fn, null, null);
            ret.native_ = value;
            return ret;
        }
    }
}
_a = auth_, _b = functions_, _c = storage_;
export function createClient(supabaseURL, supabaseKey) {
    try {
        const client = org.nativescript.supabase.SupabaseClient.createClient(supabaseURL, supabaseKey);
        return SupabaseClient.fromNative(client);
    }
    catch (e) {
        throw new Error(e.message);
    }
}
//# sourceMappingURL=index.android.js.map