import { merge, Dict, evaluate, conform, requiredKeyOf, ErrorMessage, narrow } from '@arktype/util';
import { a as TableCodegen, b as TableDeploy, U as UserTypes, E as Enums, C as Codegen } from './output-b02052a1.js';
import { Hex } from 'viem';
import { StaticAbiType, FixedArrayAbiType, fixedArrayToArray } from '@latticexyz/schema-type/internal';
import { AbiType } from '@latticexyz/config';

type get<input, key> = key extends keyof input ? input[key] : undefined;
declare function get<input, key extends PropertyKey>(input: input, key: key): get<input, key>;
type getPath<input, path extends readonly PropertyKey[]> = path extends readonly [
    infer head,
    ...infer tail extends PropertyKey[]
] ? head extends keyof input ? getPath<input[head], tail> : undefined : input;
declare function getPath<input, path extends readonly PropertyKey[]>(input: input, path: path): getPath<input, path>;
declare function hasOwnKey<obj, const key extends PropertyKey>(object: obj, key: key): object is {
    [k in key]: k extends keyof obj ? obj[k] : unknown;
} & obj;
declare function isObject<input>(input: input): input is input & object;
type mergeIfUndefined<base, merged> = merge<base, {
    [key in keyof merged]: key extends keyof base ? undefined extends base[key] ? merged[key] : base[key] : merged[key];
}>;
declare function mergeIfUndefined<base extends object, merged extends object>(base: base, merged: merged): mergeIfUndefined<base, merged>;

declare const CODEGEN_DEFAULTS: {
    readonly storeImportPath: "@latticexyz/store/src/";
    readonly userTypesFilename: "common.sol";
    readonly outputDirectory: "codegen";
    readonly indexFilename: "index.sol";
};
type CODEGEN_DEFAULTS = typeof CODEGEN_DEFAULTS;
declare const TABLE_CODEGEN_DEFAULTS: {
    readonly outputDirectory: "tables";
    readonly tableIdArgument: false;
    readonly storeArgument: false;
};
type TABLE_CODEGEN_DEFAULTS = typeof TABLE_CODEGEN_DEFAULTS;
declare const TABLE_DEPLOY_DEFAULTS: {
    readonly disabled: false;
};
type TABLE_DEPLOY_DEFAULTS = typeof TABLE_DEPLOY_DEFAULTS;
declare const TABLE_DEFAULTS: {
    readonly namespace: "";
    readonly type: "table";
};
type TABLE_DEFAULTS = typeof TABLE_DEFAULTS;
declare const CONFIG_DEFAULTS: {
    readonly namespace: "";
};
type CONFIG_DEFAULTS = typeof CONFIG_DEFAULTS;

declare const Scope: {
    readonly types: {};
};
type Scope = typeof Scope;
type AbiTypeScope = ScopeOptions<{
    [t in AbiType]: t;
}>;
declare const AbiTypeScope: AbiTypeScope;
type ScopeOptions<types extends Dict<string, AbiType> = Dict<string, AbiType>> = {
    types: types;
};
type getStaticAbiTypeKeys<schema extends SchemaInput, scope extends Scope = AbiTypeScope> = SchemaInput extends schema ? string : {
    [key in keyof schema]: scope["types"] extends {
        [_ in schema[key]]: StaticAbiType;
    } ? key : never;
}[keyof schema];
type extendScope<scope extends ScopeOptions, additionalTypes extends Dict<string, AbiType>> = evaluate<ScopeOptions<evaluate<scope["types"] & additionalTypes>>>;
declare function extendScope<scope extends ScopeOptions, additionalTypes extends Dict<string, AbiType>>(scope: scope, additionalTypes: additionalTypes): extendScope<scope, additionalTypes>;

type SchemaInput = {
    readonly [key: string]: string;
};
type ScopedSchemaInput<scope extends Scope> = {
    readonly [key: string]: keyof scope["types"];
};
type TableInput = {
    readonly schema: SchemaInput;
    readonly key: readonly string[];
    readonly tableId?: Hex;
    readonly name: string;
    readonly namespace?: string;
    readonly type?: "table" | "offchainTable";
    readonly codegen?: Partial<TableCodegen>;
    readonly deploy?: Partial<TableDeploy>;
};
type TablesInput = {
    readonly [key: string]: Omit<TableInput, "namespace" | "name">;
};
type StoreInput = {
    readonly namespace?: string;
    readonly tables?: TablesInput;
    readonly userTypes?: UserTypes;
    readonly enums?: Enums;
    readonly codegen?: Partial<Codegen>;
};
/******** Variations with shorthands ********/
type TableShorthandInput = SchemaInput | string;
type TablesWithShorthandsInput = {
    readonly [key: string]: TableInput | TableShorthandInput;
};
type StoreWithShorthandsInput = evaluate<Omit<StoreInput, "tables"> & {
    tables: TablesWithShorthandsInput;
}>;

type validateSchema<schema, scope extends Scope = AbiTypeScope> = schema extends string ? SchemaInput : {
    [key in keyof schema]: schema[key] extends FixedArrayAbiType ? schema[key] : conform<schema[key], keyof scope["types"]>;
};
declare function validateSchema<scope extends Scope = AbiTypeScope>(schema: unknown, scope?: scope): asserts schema is SchemaInput;
type resolveSchema<schema, scope extends Scope> = evaluate<{
    readonly [key in keyof schema]: {
        /** the Solidity primitive ABI type */
        readonly type: schema[key] extends FixedArrayAbiType ? fixedArrayToArray<schema[key]> : scope["types"][schema[key] & keyof scope["types"]];
        /** the user defined type or Solidity primitive ABI type */
        readonly internalType: schema[key];
    };
}>;
declare function resolveSchema<schema extends SchemaInput, scope extends Scope = AbiTypeScope>(schema: schema, scope?: scope): resolveSchema<schema, scope>;
declare function defineSchema<schema, scope extends AbiTypeScope = AbiTypeScope>(schema: validateSchema<schema, scope>, scope?: scope): resolveSchema<schema, scope>;
declare function isSchemaInput<scope extends Scope = AbiTypeScope>(input: unknown, scope?: scope): input is SchemaInput;

type ValidKeys<schema extends SchemaInput, scope extends Scope> = readonly [
    getStaticAbiTypeKeys<schema, scope>,
    ...getStaticAbiTypeKeys<schema, scope>[]
];
declare function isValidPrimaryKey<schema extends SchemaInput, scope extends Scope>(key: unknown, schema: schema, scope?: scope): key is ValidKeys<schema, scope>;
type validateKeys<validKeys extends PropertyKey, keys> = keys extends readonly string[] ? {
    readonly [i in keyof keys]: keys[i] extends validKeys ? keys[i] : validKeys;
} : readonly string[];
type ValidateTableOptions = {
    inStoreContext: boolean;
};
type requiredTableKey<inStoreContext extends boolean> = Exclude<requiredKeyOf<TableInput>, inStoreContext extends true ? "name" | "namespace" : "">;
type validateTable<input, scope extends Scope = AbiTypeScope, options extends ValidateTableOptions = {
    inStoreContext: false;
}> = {
    [key in keyof input | requiredTableKey<options["inStoreContext"]>]: key extends "key" ? validateKeys<getStaticAbiTypeKeys<conform<get<input, "schema">, SchemaInput>, scope>, get<input, key>> : key extends "schema" ? validateSchema<get<input, key>, scope> : key extends "name" | "namespace" ? options["inStoreContext"] extends true ? ErrorMessage<"Overrides of `name` and `namespace` are not allowed for tables in a store config"> : key extends keyof input ? narrow<input[key]> : never : key extends keyof TableInput ? TableInput[key] : ErrorMessage<`Key \`${key & string}\` does not exist in TableInput`>;
};
declare function validateTable<input, scope extends Scope = AbiTypeScope>(input: input, scope?: scope, options?: ValidateTableOptions): asserts input is TableInput & input;
type resolveTableCodegen<input extends TableInput> = evaluate<{
    [key in keyof TableCodegen]-?: key extends keyof input["codegen"] ? undefined extends input["codegen"][key] ? key extends "dataStruct" ? boolean : key extends keyof TABLE_CODEGEN_DEFAULTS ? TABLE_CODEGEN_DEFAULTS[key] : never : input["codegen"][key] : key extends "dataStruct" ? boolean : key extends keyof TABLE_CODEGEN_DEFAULTS ? TABLE_CODEGEN_DEFAULTS[key] : never;
}>;
declare function resolveTableCodegen<input extends TableInput>(input: input): resolveTableCodegen<input>;
type resolveTable<input, scope extends Scope = Scope> = input extends TableInput ? {
    readonly tableId: Hex;
    readonly name: input["name"];
    readonly namespace: undefined extends input["namespace"] ? typeof TABLE_DEFAULTS.namespace : input["namespace"];
    readonly type: undefined extends input["type"] ? typeof TABLE_DEFAULTS.type : input["type"];
    readonly key: Readonly<input["key"]>;
    readonly schema: resolveSchema<input["schema"], scope>;
    readonly codegen: resolveTableCodegen<input>;
    readonly deploy: mergeIfUndefined<undefined extends input["deploy"] ? {} : input["deploy"], TABLE_DEPLOY_DEFAULTS>;
} : never;
declare function resolveTable<input extends TableInput, scope extends Scope = AbiTypeScope>(input: input, scope?: scope): resolveTable<input, scope>;
declare function defineTable<input, scope extends Scope = AbiTypeScope>(input: validateTable<input, scope>, scope?: scope): resolveTable<input, scope>;

type validateTables<tables, scope extends Scope = AbiTypeScope> = {
    [key in keyof tables]: tables[key] extends object ? validateTable<tables[key], scope, {
        inStoreContext: true;
    }> : ErrorMessage<`Expected full table config.`>;
};
declare function validateTables<scope extends Scope = AbiTypeScope>(input: unknown, scope: scope): asserts input is TablesInput;
type resolveTables<tables, scope extends Scope = AbiTypeScope> = evaluate<{
    readonly [key in keyof tables]: resolveTable<mergeIfUndefined<tables[key], {
        name: key;
    }>, scope>;
}>;
declare function resolveTables<tables extends TablesInput, scope extends Scope = AbiTypeScope>(tables: tables, scope?: scope): resolveTables<tables, scope>;

type extractInternalType<userTypes extends UserTypes> = {
    [key in keyof userTypes]: userTypes[key]["type"];
};
declare function extractInternalType<userTypes extends UserTypes>(userTypes: userTypes): extractInternalType<userTypes>;
declare function isUserTypes(userTypes: unknown): userTypes is UserTypes;
type scopeWithUserTypes<userTypes, scope extends AbiTypeScope = AbiTypeScope> = UserTypes extends userTypes ? scope : userTypes extends UserTypes ? extendScope<scope, extractInternalType<userTypes>> : scope;
declare function scopeWithUserTypes<userTypes, scope extends AbiTypeScope = AbiTypeScope>(userTypes: userTypes, scope?: scope): scopeWithUserTypes<userTypes, scope>;
declare function validateUserTypes(userTypes: unknown): asserts userTypes is UserTypes;

type scopeWithEnums<enums, scope extends AbiTypeScope = AbiTypeScope> = Enums extends enums ? scope : enums extends Enums ? extendScope<scope, {
    [key in keyof enums]: "uint8";
}> : scope;
declare function scopeWithEnums<enums, scope extends AbiTypeScope = AbiTypeScope>(enums: enums, scope?: scope): scopeWithEnums<enums, scope>;
type resolveEnums<enums> = {
    readonly [key in keyof enums]: Readonly<enums[key]>;
};

type resolveCodegen<codegen> = codegen extends {} ? mergeIfUndefined<codegen, CODEGEN_DEFAULTS> : CODEGEN_DEFAULTS;
declare function resolveCodegen<codegen>(codegen: codegen): resolveCodegen<codegen>;

type extendedScope<input> = scopeWithEnums<get<input, "enums">, scopeWithUserTypes<get<input, "userTypes">>>;
declare function extendedScope<input>(input: input): extendedScope<input>;
type validateStore<store> = {
    [key in keyof store]: key extends "tables" ? validateTables<store[key], extendedScope<store>> : key extends "userTypes" ? UserTypes : key extends "enums" ? narrow<store[key]> : key extends keyof StoreInput ? StoreInput[key] : never;
};
declare function validateStore(store: unknown): asserts store is StoreInput;
type keyPrefix<store> = store extends {
    namespace: infer namespace extends string;
} ? namespace extends "" ? "" : `${namespace}__` : "";
type resolveStore<store> = {
    readonly tables: "tables" extends keyof store ? resolveTables<{
        [tableKey in keyof store["tables"] & string as `${keyPrefix<store>}${tableKey}`]: mergeIfUndefined<store["tables"][tableKey], {
            namespace: get<store, "namespace">;
            name: tableKey;
        }>;
    }, extendedScope<store>> : {};
    readonly userTypes: "userTypes" extends keyof store ? store["userTypes"] : {};
    readonly enums: "enums" extends keyof store ? resolveEnums<store["enums"]> : {};
    readonly namespace: "namespace" extends keyof store ? store["namespace"] : CONFIG_DEFAULTS["namespace"];
    readonly codegen: "codegen" extends keyof store ? resolveCodegen<store["codegen"]> : resolveCodegen<{}>;
};
declare function resolveStore<const store extends StoreInput>(store: store): resolveStore<store>;
declare function defineStore<const store>(store: validateStore<store>): resolveStore<store>;

export { AbiTypeScope as A, SchemaInput as B, ScopedSchemaInput as C, TablesInput as D, StoreInput as E, TableShorthandInput as F, TablesWithShorthandsInput as G, StoreWithShorthandsInput as H, CODEGEN_DEFAULTS as I, TABLE_CODEGEN_DEFAULTS as J, TABLE_DEPLOY_DEFAULTS as K, TABLE_DEFAULTS as L, CONFIG_DEFAULTS as M, resolveCodegen as N, scopeWithEnums as O, resolveEnums as P, extractInternalType as Q, isUserTypes as R, Scope as S, TableInput as T, scopeWithUserTypes as U, ValidKeys as V, validateUserTypes as W, getPath as a, ScopeOptions as b, getStaticAbiTypeKeys as c, resolveSchema as d, extendScope as e, defineSchema as f, get as g, hasOwnKey as h, isObject as i, isSchemaInput as j, isValidPrimaryKey as k, validateKeys as l, mergeIfUndefined as m, ValidateTableOptions as n, requiredTableKey as o, validateTable as p, resolveTableCodegen as q, resolveStore as r, resolveTable as s, defineTable as t, validateTables as u, validateSchema as v, resolveTables as w, extendedScope as x, validateStore as y, defineStore as z };
