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';
import { serialize } from './utils';
export * from './auth';
export * from './functions';
export * from './storage';
export * from './realtime';
function parseCount(count) {
    switch (count) {
        case 'exact':
            return 1 /* NSCSupabasePostgresCountOption.Exact */;
        case 'planned':
            return 2 /* NSCSupabasePostgresCountOption.Planned */;
        case 'estimated':
            return 3 /* NSCSupabasePostgresCountOption.Estimated */;
        default:
            return 0 /* NSCSupabasePostgresCountOption.None */;
    }
}
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) {
        if (args && options?.count) {
            return PostgresFilterBuilder.fromNative(this.native.rpcParamsCountError(fn, serialize(args), parseCount(options?.count)));
        }
        else if (args) {
            return PostgresFilterBuilder.fromNative(this.native.rpcParamsCountError(fn, serialize(args), 0 /* NSCSupabasePostgresCountOption.None */));
        }
        else if (options?.count) {
            return PostgresFilterBuilder.fromNative(this.native.rpcCountError(fn, parseCount(options?.count)));
        }
        else {
            return PostgresFilterBuilder.fromNative(this.native.rpcError(fn));
        }
    }
}
_a = auth_, _b = functions_, _c = storage_;
export function createClient(supabaseURL, supabaseKey) {
    try {
        const client = NSCSupabaseClient.createClientError(supabaseURL, supabaseKey);
        return SupabaseClient.fromNative(client);
    }
    catch (e) {
        throw new Error(e.message);
    }
}
//# sourceMappingURL=index.ios.js.map