import type { Overwrite } from '@takeshape/util';
import type { XMLParser } from 'fast-xml-parser';
import type { Merge, PartialDeep, SetOptional, SetRequired } from 'type-fest';
import type { SERVICE_OBJECT_PATTERN_NAME } from '../constants.ts';
import type { AnyProjectSchemaJSON, CachedFragmentConfig, CustomAuthentication, GetQueryLoaderConfig, ListQueryLoaderConfig, OAuth2Authentication, ProjectSchemaJSON, ProjectSchemaJSONV1_0_0, ProjectSchemaJSONV3_0_0, ProjectSchemaJSONV3_1_0, ProjectSchemaJSONV3_2_0, ProjectSchemaJSONV3_3_0, ProjectSchemaJSONV3_4_0, ProjectSchemaJSONV3_5_0, ProjectSchemaJSONV3_5_1, ProjectSchemaJSONV3_6_0, ProjectSchemaJSONV3_7_0, ProjectSchemaJSONV3_8_0, ProjectSchemaJSONV3_9_0, ProjectSchemaJSONV3_10_0, ProjectSchemaJSONV3_11_0, ProjectSchemaJSONV3_12_0, ProjectSchemaJSONV3_12_1, ProjectSchemaJSONV3_12_2, ProjectSchemaJSONV3_12_3, ProjectSchemaJSONV3_13_0, ProjectSchemaJSONV3_14_0, ProjectSchemaJSONV3_15_0, ProjectSchemaJSONV3_16_0, ProjectSchemaJSONV3_17_0, ProjectSchemaJSONV3_17_1, ProjectSchemaJSONV3_18_0, ProjectSchemaJSONV3_18_1, ProjectSchemaJSONV3_18_2, ProjectSchemaJSONV3_19_0, ProjectSchemaJSONV3_20_0, ProjectSchemaJSONV3_21_0, ProjectSchemaJSONV3_22_0, ProjectSchemaJSONV3_23_0, PropertySchema, QueryJSON, Ref, ServiceAuthentication, ServiceConfig, ServiceMapJSON, ShapeJSON, ShapeLoaders, ToolJSON } from '../project-schema/index.ts';
export type ProjectSchemaJSONWithVersion = ProjectSchemaJSONV3_23_0 | ProjectSchemaJSONV3_22_0 | ProjectSchemaJSONV3_21_0 | ProjectSchemaJSONV3_20_0 | ProjectSchemaJSONV3_19_0 | ProjectSchemaJSONV3_18_2 | ProjectSchemaJSONV3_18_1 | ProjectSchemaJSONV3_18_0 | ProjectSchemaJSONV3_17_1 | ProjectSchemaJSONV3_17_0 | ProjectSchemaJSONV3_16_0 | ProjectSchemaJSONV3_15_0 | ProjectSchemaJSONV3_14_0 | ProjectSchemaJSONV3_13_0 | ProjectSchemaJSONV3_12_3 | ProjectSchemaJSONV3_12_2 | ProjectSchemaJSONV3_12_1 | ProjectSchemaJSONV3_12_0 | ProjectSchemaJSONV3_11_0 | ProjectSchemaJSONV3_10_0 | ProjectSchemaJSONV3_9_0 | ProjectSchemaJSONV3_8_0 | ProjectSchemaJSONV3_7_0 | ProjectSchemaJSONV3_6_0 | ProjectSchemaJSONV3_5_1 | ProjectSchemaJSONV3_5_0 | ProjectSchemaJSONV3_4_0 | ProjectSchemaJSONV3_3_0 | ProjectSchemaJSONV3_2_0 | ProjectSchemaJSONV3_1_0 | ProjectSchemaJSONV3_0_0 | ProjectSchemaJSONV1_0_0;
export declare const projectSchemaImportOptionalProps: readonly ["projectId", "locales", "defaultLocale", "author"];
export declare const legacyProjectSchemaImportOptionalProps: readonly ["created", "updated", "version", "dataKey"];
export type ProjectSchemaImport = SetOptional<AnyProjectSchemaJSON, (typeof projectSchemaImportOptionalProps)[number]>;
export type Content = {
    [name: string]: any;
    _id: string;
};
export type ServiceInfo = {
    service: string;
    fieldName: string;
    path: string[];
    generators: Record<typeof SERVICE_OBJECT_PATTERN_NAME, PatternGenerator | undefined>;
};
/**
 * Remote service configuration types
 */
/**
 * Old service authentication
 * @deprecated
 */
export type ServiceConfigAccessToken = {
    accessToken: string;
    refreshToken?: string;
    scope?: string;
};
export type ServiceKey = string;
export type ServiceMap = Map<ServiceKey, ServiceConfig>;
export type PatternGenerator = {
    version: string;
    currentVersion: string;
    idFieldName: string;
    serviceObjectType: string;
};
export type Headers = Record<string, string | string[]>;
type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'HEAD' | 'DELETE' | 'OPTIONS' | 'TRACE' | 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete' | 'options' | 'trace';
export type AllowedRetryOptions = number | Partial<{
    limit: number;
    methods: Method[];
    statusCodes: number[];
    errorCodes: string[];
    maxRetryAfter: number;
    backoffLimit: number;
    noise: number;
}>;
export type RESTServiceConfig = Overwrite<ServiceConfig, {
    serviceType: 'rest';
    options: {
        [name: string]: any;
        endpoint: string;
        headers?: Headers;
        timeout?: number;
        retry?: AllowedRetryOptions;
        requestConcurrency?: number;
        fastXmlParser?: ConstructorParameters<typeof XMLParser>[0];
    };
}>;
export type GraphQLServiceConfig = Overwrite<ServiceConfig, {
    serviceType: 'graphql';
    options: {
        [name: string]: any;
        endpoint: string;
        headers?: Headers;
        timeout?: number;
        requestConcurrency?: number;
    };
}>;
export type OpenAPIServiceConfig = Merge<ServiceConfig, {
    serviceType: 'openapi';
    options: {
        [name: string]: any;
        endpoint: string;
        spec: string;
        headers?: Headers;
        timeout?: number;
        retry?: AllowedRetryOptions;
        requestConcurrency?: number;
        useRestfulNames?: boolean;
        introspectedAt?: string;
        transformVersion?: string;
    };
}>;
export type EncryptedServiceConfig = Overwrite<ServiceConfig, {
    authentication: string;
}>;
export type ServiceConfigWithOAuth2Authentication = Merge<ServiceConfig, {
    authentication: OAuth2Authentication;
}>;
export type ServiceConfigWithCustomAuthentication = Merge<ServiceConfig, {
    authentication: CustomAuthentication;
}>;
/**
 * Support null sentinels for authentication
 */
export type ServiceConfigWithNullSentinelAuthentication = Overwrite<ServiceConfig, {
    authentication?: ServiceAuthentication | null;
}>;
/**
 * A type suitable for service object updates, mostly concerns authentication
 * requirements.
 */
export type ServiceConfigUpdate = SetRequired<PartialDeep<ServiceConfigWithNullSentinelAuthentication>, 'authenticationType'>;
export type LatestProjectSchemaWithServices = {
    services: ServiceMapJSON;
} & ProjectSchemaJSON;
/**
 * Types of args
 */
export declare enum ArgsType {
    '@args' = "@args",
    args = "args"
}
export type SchemaWithArgs = PropertySchema | QueryJSON;
/**
 * Types supporting schema iterators
 */
export type SchemaPropertyName = string;
export type SchemaPropertyNode = [SchemaPropertyName, PropertySchema];
export type SchemaPropertyIterator = SchemaPropertyNode[];
export type ShopifyServiceConfig = Overwrite<ServiceConfig, {
    serviceType: 'graphql';
    provider: 'shopify';
    options: {
        shop: string;
        endpoint: string;
    };
}>;
export type SchemaPath = Array<string | number>;
export type LayerSchema = Pick<ProjectSchemaJSON, 'shapes' | 'queries' | 'mutations' | 'tools' | 'schemaVersion'>;
export type ServiceLayers = Record<string, LayerState>;
export type UndefinedLayerState = {
    id: string;
    schema: undefined;
    status: 'disconnected' | 'error' | 'notAvailable';
};
export type DefinedLayerState = {
    id: string;
    schema: LayerSchema;
    status: 'ok';
};
export type LayerState = UndefinedLayerState | DefinedLayerState;
export type LayerStatus = LayerState['status'];
export type UndefinedLayerStatus = UndefinedLayerState['status'];
/**
 * Shapes
 */
export type ShapeRefs = Ref[];
/**
 * Relationships
 */
export type PropertySchemaWithRelationship = PropertySchema & {
    '@resolver': {
        name: 'shapedb:getRelated';
        service: 'shapedb';
        options?: {
            nullable?: boolean;
        };
    };
};
/**
 * New relationship data, drawn from a PropertySchema.
 */
export type Relationship = {
    isMultiple: boolean;
    refs: ShapeRefs;
    hasBackreference: boolean;
    backreferenceName?: string;
};
/**
 * The old relationship format, used in client UI.
 */
export type LegacyRelationship = {
    shapeIds: string[];
    type?: 'single' | 'multiple';
};
export type RelationshipEnv = {
    shapeId: string;
    path: string[];
    hasBackreference: boolean;
    relatedName?: string;
    schema: PropertySchema;
    shapeName: string;
};
export type CachedShape = SetRequired<ShapeJSON, 'loaders' | 'cache'>;
export type CachedShapeMap = Record<string, CachedShape>;
export type ListQueryIndexingConfig = CachedFragmentConfig & ListQueryLoaderConfig & {
    shapeName: string;
    idField: string;
};
export type GetQueryIndexingConfig = CachedFragmentConfig & GetQueryLoaderConfig & {
    shapeName: string;
    idField: string;
};
export type MeshShape = SetRequired<ShapeJSON, 'joins'>;
export type ReferenceableShape = ShapeJSON & {
    loaders: SetRequired<ShapeLoaders, 'get'>;
};
export type NamedToolJSON = ToolJSON & {
    name: string;
};
export {};
