import { evaluate, narrow, ErrorMessage, conform } from '@arktype/util';
import { StoreInput, StoreWithShorthandsInput, resolveTable, mergeIfUndefined, getPath, extendedScope, Scope, AbiTypeScope, validateTables, UserTypes, resolveStore, Store } from '@latticexyz/store/config/v2';
import { M as Module } from './output-de05b96e.js';
import { S as SYSTEM_DEFAULTS } from './defaults-8b2664e0.js';

type SystemInput = {
    /** The full resource selector consists of namespace and name */
    name?: string;
    /**
     * Register function selectors for the system in the World.
     * Defaults to true.
     * Note:
     * - For root systems all World function selectors will correspond to the system's function selectors.
     * - For non-root systems, the World function selectors will be <namespace>__<function>.
     */
    registerFunctionSelectors?: boolean;
    /** If openAccess is true, any address can call the system */
    openAccess?: boolean;
    /** An array of addresses or system names that can access the system */
    accessList?: string[];
};
type SystemsInput = {
    [key: string]: SystemInput;
};
type DeployInput = {
    /**
     * Script to execute after the deployment is complete (Default "PostDeploy").
     * Script must be placed in the forge scripts directory (see foundry.toml) and have a ".s.sol" extension.
     */
    postDeployScript?: string;
    /** Directory to write the deployment info to (Default "./deploys") */
    deploysDirectory?: string;
    /** JSON file to write to with chain -> latest world deploy address (Default "./worlds.json") */
    worldsFile?: string;
    /** Deploy the World as an upgradeable proxy */
    upgradeableWorldImplementation?: boolean;
};
type CodegenInput = {
    /** The name of the World interface to generate. (Default `IWorld`) */
    worldInterfaceName?: string;
    /** Directory to output system and world interfaces of `worldgen` (Default "world") */
    worldgenDirectory?: string;
    /** Path for world package imports. Default is "@latticexyz/world/src/" */
    worldImportPath?: string;
};
type WorldInput = evaluate<StoreInput & {
    namespaces?: NamespacesInput;
    /**
     * Contracts named *System will be deployed by default
     * as public systems at `namespace/ContractName`, unless overridden
     *
     * The key is the system name (capitalized).
     * The value is a SystemConfig object.
     */
    systems?: SystemsInput;
    /** System names to exclude from automatic deployment */
    excludeSystems?: string[];
    /** Modules to in the World */
    modules?: Module[];
    /** Deploy config */
    deploy?: DeployInput;
    /** Codegen config */
    codegen?: CodegenInput;
}>;
type NamespacesInput = {
    [key: string]: NamespaceInput;
};
type NamespaceInput = Pick<StoreInput, "tables">;
/******** Variations with shorthands ********/
type WorldWithShorthandsInput = Omit<WorldInput, "tables"> & Pick<StoreWithShorthandsInput, "tables">;

type namespacedTableKeys<world> = world extends {
    namespaces: infer namespaces;
} ? {
    [k in keyof namespaces]: namespaces[k] extends {
        tables: infer tables;
    } ? `${k & string}__${keyof tables & string}` : never;
}[keyof namespaces] : never;
type validateNamespaces<namespaces, scope extends Scope = AbiTypeScope> = {
    [namespace in keyof namespaces]: {
        [key in keyof namespaces[namespace]]: key extends "tables" ? validateTables<namespaces[namespace][key], scope> : namespaces[namespace][key];
    };
};
declare function validateNamespaces<scope extends Scope = AbiTypeScope>(namespaces: unknown, scope: scope): asserts namespaces is NamespacesInput;
type resolveNamespacedTables<world> = "namespaces" extends keyof world ? {
    readonly [key in namespacedTableKeys<world>]: key extends `${infer namespace}__${infer table}` ? resolveTable<mergeIfUndefined<getPath<world, ["namespaces", namespace, "tables", table]>, {
        name: table;
        namespace: namespace;
    }>, extendedScope<world>> : never;
} : {};

declare const CODEGEN_DEFAULTS: {
    readonly worldInterfaceName: "IWorld";
    readonly worldgenDirectory: "world";
    readonly worldImportPath: "@latticexyz/world/src/";
};
type CODEGEN_DEFAULTS = typeof CODEGEN_DEFAULTS;
declare const DEPLOY_DEFAULTS: {
    readonly customWorldContract: undefined;
    readonly postDeployScript: "PostDeploy";
    readonly deploysDirectory: "./deploys";
    readonly worldsFile: "./worlds.json";
    readonly upgradeableWorldImplementation: false;
};
type DEPLOY_DEFAULTS = typeof DEPLOY_DEFAULTS;
declare const CONFIG_DEFAULTS: {
    readonly systems: {};
    readonly tables: {};
    readonly excludeSystems: string[];
    readonly modules: readonly [];
    readonly codegen: {
        readonly worldInterfaceName: "IWorld";
        readonly worldgenDirectory: "world";
        readonly worldImportPath: "@latticexyz/world/src/";
    };
    readonly deploy: {
        readonly customWorldContract: undefined;
        readonly postDeployScript: "PostDeploy";
        readonly deploysDirectory: "./deploys";
        readonly worldsFile: "./worlds.json";
        readonly upgradeableWorldImplementation: false;
    };
};
type CONFIG_DEFAULTS = typeof CONFIG_DEFAULTS;

type resolveSystems<systems extends SystemsInput> = {
    [system in keyof systems]: mergeIfUndefined<systems[system], typeof SYSTEM_DEFAULTS>;
};
declare function resolveSystems<systems extends SystemsInput>(systems: systems): resolveSystems<systems>;

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

type resolveDeploy<deploy> = deploy extends {} ? mergeIfUndefined<deploy, DEPLOY_DEFAULTS> : DEPLOY_DEFAULTS;
declare function resolveDeploy<deploy>(deploy: deploy): resolveDeploy<deploy>;

type validateWorld<world> = {
    readonly [key in keyof world]: key extends "tables" ? validateTables<world[key], extendedScope<world>> : key extends "userTypes" ? UserTypes : key extends "enums" ? narrow<world[key]> : key extends "namespaces" ? ErrorMessage<`Namespaces config will be enabled soon.`> : key extends keyof WorldInput ? conform<world[key], WorldInput[key]> : world[key];
};
declare function validateWorld(world: unknown): asserts world is WorldInput;
type resolveWorld<world> = evaluate<resolveStore<world> & mergeIfUndefined<{
    tables: resolveNamespacedTables<world>;
} & Omit<{
    [key in keyof world]: key extends "systems" ? resolveSystems<world[key] & SystemsInput> : key extends "deploy" ? resolveDeploy<world[key]> : key extends "codegen" ? resolveCodegen<world[key]> : world[key];
}, "namespaces" | keyof Store>, CONFIG_DEFAULTS>>;
declare function resolveWorld<const world extends WorldInput>(world: world): resolveWorld<world>;
declare function defineWorld<const world>(world: validateWorld<world>): resolveWorld<world>;

export { WorldWithShorthandsInput as W, validateNamespaces as a, defineWorld as d, resolveWorld as r, validateWorld as v };
