import { LogLevelLabel } from '@storm-software/config-tools/types';
import { DotenvConfiguration, TypeDefinitionParameter } from '@stryke/types/configuration';

type LogFn = (type: LogLevelLabel, ...args: string[]) => void;
interface DotenvTypeDefinitionOptions {
    /**
     * A path to the type definition for the expected env configuration parameters. This value can include both a path to the typescript file and the name of the type definition to use separated by a `":"` or `"#"` character. For example: `"./src/types/env.ts#DotenvConfiguration"`.
     *
     * @remarks
     * If a value is not provided for this option, the plugin will attempt to infer the type definition from the `storm.dotenv.types.variables` object in the project's `package.json` file.
     */
    variables?: TypeDefinitionParameter;
    /**
     * A path to the type definition for the expected env secret parameters. This value can include both a path to the typescript file and the name of the type definition to use separated by a `":"` or `"#"` character. For example: `"./src/types/env.ts#DotenvSecrets"`.
     *
     * @remarks
     * If a value is not provided for this option, the plugin will attempt to infer the type definition from the `storm.dotenv.types.secrets` object in the project's `package.json` file.
     */
    secrets?: TypeDefinitionParameter;
}
interface DotenvOptions extends DotenvConfiguration {
    /**
     * The type definitions for the environment variables
     *
     * @remarks
     * If a value is not provided for this option, the plugin will attempt to infer the type definition from the `storm.dotenv.types` object in the project's `package.json` file.
     */
    types?: DotenvTypeDefinitionOptions | string;
    /**
     * Should the plugin replace the env variables in the source code with their values?
     *
     * @remarks
     * This option is set to `true` when building an application project.
     *
     * @defaultValue false
     */
    replace?: boolean;
}
type PluginConfig = [string, Record<string, any>];
interface ProjectConfig {
    /**
     * The name of the project
     */
    name?: string;
    /**
     * {@inheritdoc TypeScriptBuildResolvedOptions.projectRoot}
     */
    projectRoot: string;
    /**
     * The type of project being built
     *
     * @defaultValue "application"
     */
    projectType?: "application" | "library";
    /**
     * The platform to build the project for
     */
    platform?: "node" | "browser" | "neutral";
    /**
     * A list of resolvable paths to presets used during the build process
     */
    presets?: Array<string | PluginConfig>;
    /**
     * A list of resolvable paths to plugins used during the build process
     */
    plugins?: Array<string | PluginConfig>;
    /**
     * Options to control .env file processing
     */
    dotenv?: DotenvOptions;
    /**
     * Should the Storm Stack CLI processes skip installing missing packages?
     *
     * @remarks
     * This option is useful for CI/CD environments where the installation of packages is handled by a different process.
     *
     * @defaultValue false
     */
    skipInstalls?: boolean;
    /**
     * Should the compiler processes skip any improvements that make use of cache?
     *
     * @defaultValue false
     */
    skipCache?: boolean;
    /**
     * Should linting be skipped for this project?
     *
     * @defaultValue false
     */
    skipLint?: boolean;
    /**
     * Should the esbuild processes skip the bundling of node_modules?
     *
     * @defaultValue false
     */
    skipNodeModulesBundle?: boolean;
    /**
     * A list of external packages to exclude from the bundled code
     */
    external?: string[];
    /**
     * A list of packages that should be included in the bundled code
     */
    noExternal?: string[];
    /**
     * The path (relative to the workspace root) to the file that will be used to generate the errors map
     *
     * @remarks
     * This file will be generated by the Babel plugin (if it doesn't already exist) and will contain list of error codes/messages that can be thrown by the application.
     *
     * @defaultValue "tools/errors/codes.json"
     */
    errorsFile?: string;
}
type ApplicationProjectConfig = ProjectConfig & {
    /**
     * The entry point for the project
     *
     * @remarks
     * This is only used for applications. Libraries will have a separate entry point added for each file.
     */
    entry?: TypeDefinitionParameter | TypeDefinitionParameter[];
    /**
     * The type of project being built
     */
    projectType: "application";
};
type NodeProjectConfig = ProjectConfig & {
    /**
     * The platform to build the project for
     *
     * @defaultValue "node"
     */
    platform: "node";
};
type LibraryProjectConfig = ProjectConfig & {
    /**
     * The type of project being built
     */
    projectType: "library";
};

export type { ApplicationProjectConfig, DotenvOptions, DotenvTypeDefinitionOptions, LibraryProjectConfig, LogFn, NodeProjectConfig, PluginConfig, ProjectConfig };
