import { __ΩEnvInterface, __ΩSecretsInterface } from "../types/runtime.mjs";
import { __ΩEnvPluginContext } from "../types/plugin.mjs";
import { joinPaths } from "../node_modules/.pnpm/@stryke_path@0.26.4/node_modules/@stryke/path/dist/join-paths.mjs";
import { isParentPath } from "../node_modules/.pnpm/@stryke_path@0.26.4/node_modules/@stryke/path/dist/is-parent-path.mjs";
import { getEnvDefaultTypeDefinition, getSecretsDefaultTypeDefinition, readEnvTypeReflection, readSecretsReflection } from "./persistence.mjs";
import { ReflectionClass, ReflectionKind, __ΩTypeClass, __ΩTypeObjectLiteral, merge, resolveClassType } from "@powerlines/deepkit/vendor/type";
import { titleCase } from "@stryke/string-format/title-case";
import { reflectType } from "@powerlines/deepkit/reflect-type";

//#region src/helpers/reflect.ts
function __assignType(fn, args) {
	fn.__type = args;
	return fn;
}
function mergeEnvReflections(context, reflections) {
	return createEnvReflection(context, { type: merge(reflections.map(__assignType((reflection) => reflection.type, [
		"reflection",
		"",
		"P\"2!\"/\""
	]))) });
}
mergeEnvReflections.__type = [
	() => __ΩEnvPluginContext,
	"context",
	() => ReflectionClass,
	"reflections",
	() => ReflectionClass,
	"mergeEnvReflections",
	"Pn!2\"P\"7#F2$P\"7%/&"
];
function mergeSecretsReflections(context, reflections) {
	return createSecretsReflection(context, { type: merge(reflections.map(__assignType((reflection) => reflection.type, [
		"reflection",
		"",
		"P\"2!\"/\""
	]))) });
}
mergeSecretsReflections.__type = [
	() => __ΩEnvPluginContext,
	"context",
	() => ReflectionClass,
	"reflections",
	() => ReflectionClass,
	"mergeSecretsReflections",
	"Pn!2\"P\"7#F2$P\"7%/&"
];
const __ΩCreateEnvReflectionOptions = [
	() => __ΩTypeObjectLiteral,
	() => __ΩTypeClass,
	"type",
	() => ReflectionClass,
	"superReflection",
	"CreateEnvReflectionOptions",
	"PPn!n\"J4#8P\"7$4%8Mw&y"
];
var BaseEnv = class {
	PLATFORM = "neutral";
	MODE = "production";
	DEBUG = false;
	TEST = false;
	MINIMAL = false;
	NO_COLOR = false;
	FORCE_COLOR = false;
	FORCE_HYPERLINK = false;
	STACKTRACE = false;
	INCLUDE_ERROR_DATA = false;
	CI = false;
	static __type = [
		"APP_NAME",
		"APP_VERSION",
		"BUILD_ID",
		"BUILD_TIMESTAMP",
		"BUILD_CHECKSUM",
		"RELEASE_ID",
		"RELEASE_TAG",
		"ORGANIZATION",
		"node",
		"browser",
		"neutral",
		"PLATFORM",
		function() {
			return "neutral";
		},
		"development",
		"test",
		"production",
		"MODE",
		function() {
			return "production";
		},
		"ENVIRONMENT",
		"DEBUG",
		function() {
			return false;
		},
		"TEST",
		function() {
			return false;
		},
		"MINIMAL",
		function() {
			return false;
		},
		"NO_COLOR",
		function() {
			return false;
		},
		"FORCE_COLOR",
		function() {
			return false;
		},
		"FORCE_HYPERLINK",
		function() {
			return false;
		},
		"STACKTRACE",
		function() {
			return false;
		},
		"INCLUDE_ERROR_DATA",
		function() {
			return false;
		},
		"ERROR_URL",
		"DEFAULT_TIMEZONE",
		"DEFAULT_LOCALE",
		"CI",
		function() {
			return false;
		},
		() => __ΩEnvInterface,
		"BaseEnv",
		"&3!&3\"&3#&3$&3%&3&&3'&3(P.).*.+J3,>-P.../.0J31>2&33)34>5)36>7)38>9)3:>;P')J3<>=P')J3>>?)3@>A)3B>C&3D&3E&3F)3G>H5nIx\"wJ"
	];
};
var BaseSecrets = class {
	static __type = [
		"ENCRYPTION_KEY",
		() => __ΩSecretsInterface,
		"BaseSecrets",
		"&3!5n\"x\"w#"
	];
};
function createEnvReflection(context, options = {}) {
	const parent = options.superReflection ?? new ReflectionClass({
		kind: ReflectionKind.class,
		description: `The base environment configuration definition for the ${titleCase(context.config.name)} project.`,
		classType: BaseEnv,
		types: [],
		implements: [{
			kind: ReflectionKind.objectLiteral,
			typeName: "EnvInterface",
			description: `The environment configuration interface definition for the ${titleCase(context.config.name)} project.`,
			types: []
		}]
	});
	parent.name = "Env";
	const result = new ReflectionClass(options.type ?? {
		kind: ReflectionKind.objectLiteral,
		typeName: "Env",
		description: `A schema describing the list of available environment variables that can be used by the ${context.config.name ? `${titleCase(context.config.name)} application` : "application"}.`,
		types: []
	}, parent);
	result.name = "Env";
	return result;
}
createEnvReflection.__type = [
	() => __ΩEnvPluginContext,
	"context",
	() => __ΩCreateEnvReflectionOptions,
	"options",
	() => ({}),
	() => ReflectionClass,
	"createEnvReflection",
	"Pn!2\"n#2$>%P\"7&/'"
];
function createSecretsReflection(context, options = {}) {
	const parent = options.superReflection ?? new ReflectionClass({
		kind: ReflectionKind.class,
		description: `The base secrets configuration definition for the ${titleCase(context.config.name)} project.`,
		classType: BaseSecrets,
		types: [],
		implements: [{
			kind: ReflectionKind.objectLiteral,
			typeName: "SecretsInterface",
			description: `The secrets configuration interface definition for the ${titleCase(context.config.name)} project.`,
			types: []
		}]
	});
	parent.name = "Secrets";
	const result = new ReflectionClass(options.type ?? {
		kind: ReflectionKind.objectLiteral,
		typeName: "Secrets",
		description: `A schema describing the list of available environment secrets that can be used by the ${context.config.name ? `${titleCase(context.config.name)} application` : "application"}.`,
		types: []
	}, parent);
	result.name = "Secrets";
	return result;
}
createSecretsReflection.__type = [
	() => __ΩEnvPluginContext,
	"context",
	() => __ΩCreateEnvReflectionOptions,
	"options",
	() => ({}),
	() => ReflectionClass,
	"createSecretsReflection",
	"Pn!2\"n#2$>%P\"7&/'"
];
async function reflectEnv(context, file, name) {
	let config;
	if (file) config = resolveClassType(await reflectType(context, {
		file: !isParentPath(file, context.workspaceConfig.workspaceRoot) ? joinPaths(context.workspaceConfig.workspaceRoot, file) : file,
		name
	}));
	const defaultConfigType = await reflectType(context, await getEnvDefaultTypeDefinition(context));
	return mergeEnvReflections(context, [
		await readEnvTypeReflection(context, "env"),
		config,
		resolveClassType(defaultConfigType)
	].filter(Boolean));
}
reflectEnv.__type = [
	() => __ΩEnvPluginContext,
	"context",
	"file",
	"name",
	"reflectEnv",
	"Pn!2\"&2#8&2$8\"/%"
];
async function reflectSecrets(context, file, name) {
	let config;
	if (file) config = resolveClassType(await reflectType(context, {
		file: !isParentPath(file, context.workspaceConfig.workspaceRoot) ? joinPaths(context.workspaceConfig.workspaceRoot, file) : file,
		name
	}));
	const defaultSecretsType = await reflectType(context, await getSecretsDefaultTypeDefinition(context));
	return mergeSecretsReflections(context, [
		await readSecretsReflection(context),
		config,
		resolveClassType(defaultSecretsType)
	].filter(Boolean));
}
reflectSecrets.__type = [
	() => __ΩEnvPluginContext,
	"context",
	"file",
	"name",
	"reflectSecrets",
	"Pn!2\"&2#8&2$8\"/%"
];

//#endregion
export { BaseEnv, BaseSecrets, __ΩCreateEnvReflectionOptions, createEnvReflection, createSecretsReflection, mergeEnvReflections, mergeSecretsReflections, reflectEnv, reflectSecrets };
//# sourceMappingURL=reflect.mjs.map