import { REALM_OPERATION_MAP, REALM_SERVICE_METHODS, type RealmHttpMethod, type RealmOperationKey, type RealmOperationParameter, type RealmOperationResult } from './operation-map.js';
import type { operations } from './schema.js';
export type RealmRawRequestInput = {
    method: RealmHttpMethod;
    path: string;
    pathParams?: Record<string, string | number>;
    query?: Record<string, unknown>;
    body?: unknown;
    headers?: Record<string, string>;
    timeoutMs?: number;
    signal?: AbortSignal;
};
export type RealmRequestExecutor = (input: RealmRawRequestInput) => Promise<unknown>;
export type RealmOperationInvoker<Args extends unknown[] = unknown[], Result = unknown> = (...args: Args) => Promise<Result>;
export type RealmServiceHandle = Record<string, RealmOperationInvoker>;
type OperationDefinitionByKey<K extends RealmOperationKey> = (typeof REALM_OPERATION_MAP)[K];
type ValueOf<T> = T[keyof T];
type ResolveNever<T, Fallback> = [T] extends [never] ? Fallback : T;
type OperationParameterValueByDefinition<Parameter extends RealmOperationParameter> = Parameter['valueType'] extends 'string' ? string : Parameter['valueType'] extends 'number' ? number : Parameter['valueType'] extends 'boolean' ? boolean : Parameter['valueType'] extends 'string[]' ? string[] : Parameter['valueType'] extends 'number[]' ? number[] : Parameter['valueType'] extends 'boolean[]' ? boolean[] : unknown;
type OperationParameterValue<K extends RealmOperationKey, Parameter extends RealmOperationParameter> = ResolveNever<OperationParameterValueByDefinition<Parameter>, unknown>;
type OperationParameterTupleByRequired<K extends RealmOperationKey, Parameters extends readonly RealmOperationParameter[], Required extends boolean> = Parameters extends readonly [infer Head, ...infer Tail] ? Head extends RealmOperationParameter ? Tail extends readonly RealmOperationParameter[] ? Head['required'] extends Required ? [OperationParameterValue<K, Head>, ...OperationParameterTupleByRequired<K, Tail, Required>] : OperationParameterTupleByRequired<K, Tail, Required> : [] : [] : [];
type OperationRequestBody<K extends RealmOperationKey> = OperationDefinitionByKey<K>['operationId'] extends keyof operations ? operations[OperationDefinitionByKey<K>['operationId']] extends {
    requestBody?: infer RequestBody;
} ? RequestBody extends {
    content?: infer Content;
} ? ValueOf<NonNullable<Content>> : never : never : never;
type OperationBodyValue<K extends RealmOperationKey> = ResolveNever<OperationRequestBody<K>, unknown>;
type OperationBodyTuple<K extends RealmOperationKey> = OperationDefinitionByKey<K>['hasBody'] extends true ? OperationDefinitionByKey<K>['bodyRequired'] extends true ? [OperationBodyValue<K>] : [OperationBodyValue<K>?] : [];
type OperationRequiredParameterTuple<K extends RealmOperationKey> = OperationParameterTupleByRequired<K, OperationDefinitionByKey<K>['parameters'], true>;
type OperationOptionalParameterValueTuple<K extends RealmOperationKey> = OperationParameterTupleByRequired<K, OperationDefinitionByKey<K>['parameters'], false>;
type OptionalizeTrailingTuple<Tuple extends readonly unknown[]> = Tuple extends readonly [infer Head, ...infer Tail] ? Tail extends readonly unknown[] ? [Head?, ...OptionalizeTrailingTuple<Tail>] : [Head?] : [];
type OperationOptionalParameterTuple<K extends RealmOperationKey> = OptionalizeTrailingTuple<OperationOptionalParameterValueTuple<K>>;
type OperationPathAndQueryArgs<K extends RealmOperationKey> = [
    ...OperationRequiredParameterTuple<K>,
    ...OperationOptionalParameterTuple<K>
];
type OperationPathAndQueryAndBodyArgs<K extends RealmOperationKey> = OperationOptionalParameterValueTuple<K> extends [] ? [
    ...OperationRequiredParameterTuple<K>,
    ...OperationBodyTuple<K>
] : [
    ...OperationRequiredParameterTuple<K>,
    ...OperationOptionalParameterValueTuple<K>,
    ...OperationBodyTuple<K>
];
type OperationInvokerArgs<K extends RealmOperationKey> = [
    ...(OperationDefinitionByKey<K>['hasBody'] extends true ? OperationPathAndQueryAndBodyArgs<K> : OperationPathAndQueryArgs<K>),
    options?: ServiceCallOptions
];
type OperationInvokerByKey<K extends RealmOperationKey> = RealmOperationInvoker<OperationInvokerArgs<K>, RealmOperationResult<K>>;
type ServiceHandleByName<S extends keyof typeof REALM_SERVICE_METHODS> = {
    -readonly [M in keyof (typeof REALM_SERVICE_METHODS)[S]]: OperationInvokerByKey<(typeof REALM_SERVICE_METHODS)[S][M] & RealmOperationKey>;
};
export type RealmGeneratedServiceRegistry = {
    -readonly [S in keyof typeof REALM_SERVICE_METHODS]: ServiceHandleByName<S>;
};
type ServiceCallOptions = {
    headers?: Record<string, string>;
    timeoutMs?: number;
    signal?: AbortSignal;
};
export declare function createRealmServiceRegistry(execute: RealmRequestExecutor): RealmGeneratedServiceRegistry;
export {};
//# sourceMappingURL=service-registry.d.ts.map