import { SchemaProcessor } from "./SchemaProcessor.js";
import { z } from "@hono/zod-openapi";

//#region src/domains/run/utils/artifact-component-schema.ts
/**
* Standard artifact reference component schema for tool responses
*/
var ArtifactReferenceSchema = class ArtifactReferenceSchema {
	static ARTIFACT_PROPS_SCHEMA = {
		type: "object",
		properties: {
			artifact_id: {
				type: "string",
				description: "The artifact_id from your artifact:create tag. Must match exactly."
			},
			tool_call_id: {
				type: "string",
				description: "The EXACT tool_call_id from tool execution (call_xyz789 or toolu_abc123). NEVER invent or make up IDs."
			}
		},
		required: ["artifact_id", "tool_call_id"]
	};
	/**
	* Get the standard Zod schema for artifact reference components
	*/
	static getSchema() {
		return z.object({
			id: z.string(),
			name: z.literal("Artifact"),
			props: z.fromJSONSchema(ArtifactReferenceSchema.ARTIFACT_PROPS_SCHEMA)
		});
	}
	/**
	* Get complete DataComponent by adding missing fields to base definition
	*/
	static getDataComponent(tenantId, projectId = "") {
		return {
			id: "The artifact_id from your artifact:create tag. Must match exactly.",
			tenantId,
			projectId,
			name: "Artifact",
			description: "Reference to artifacts created from tool results that grounds information in verifiable sources.",
			props: ArtifactReferenceSchema.ARTIFACT_PROPS_SCHEMA
		};
	}
};
/**
* Standard artifact creation component schema for data components
*/
var ArtifactCreateSchema = class {
	/**
	* Generate artifact create schemas - one for each artifact component type
	* @param artifactComponents - The available artifact components to generate schemas for
	* @returns Array of Zod schemas, one for each artifact component
	*/
	static getSchemas(artifactComponents) {
		return artifactComponents.map((component) => {
			const enhancedSchema = component.props ? SchemaProcessor.enhanceSchemaWithJMESPathGuidance(component.props) : {
				type: "object",
				properties: {}
			};
			const propsSchema = {
				type: "object",
				properties: {
					id: {
						type: "string",
						description: `Unique artifact identifier for ${component.name} (e.g., "${component.name.toLowerCase()}-1")`
					},
					tool_call_id: {
						type: "string",
						description: "The EXACT tool_call_id from tool execution (call_xyz789 or toolu_abc123). NEVER invent or make up IDs."
					},
					type: {
						type: "string",
						enum: [component.name],
						description: `Artifact type - must be "${component.name}"`
					},
					base_selector: {
						type: "string",
						description: "JMESPath selector starting with \"result.\" to navigate to ONE specific item. Details selector will be relative to this selection. Use filtering to avoid arrays (e.g., \"result.items[?type=='guide']\")."
					},
					details_selector: enhancedSchema
				},
				required: [
					"id",
					"tool_call_id",
					"type",
					"base_selector"
				]
			};
			const normalizedPropsSchema = SchemaProcessor.makeAllPropertiesRequired(propsSchema);
			return z.object({
				id: z.string(),
				name: z.literal(`ArtifactCreate_${component.name}`),
				props: z.fromJSONSchema(normalizedPropsSchema)
			});
		});
	}
	/**
	* Get DataComponents for artifact creation - one for each artifact component type
	* @param artifactComponents - The available artifact components to generate schemas for
	* @returns Array of DataComponent definitions, one for each artifact component
	*/
	static getDataComponents(tenantId, projectId = "", artifactComponents) {
		return artifactComponents.map((component) => {
			const enhancedSchema = component.props ? SchemaProcessor.enhanceSchemaWithJMESPathGuidance(component.props) : {
				type: "object",
				properties: {}
			};
			const propsSchema = {
				type: "object",
				properties: {
					id: {
						type: "string",
						description: `Unique artifact identifier for ${component.name} (e.g., "${component.name.toLowerCase()}-1")`
					},
					tool_call_id: {
						type: "string",
						description: "The EXACT tool_call_id from tool execution (call_xyz789 or toolu_abc123). NEVER invent or make up IDs."
					},
					type: {
						type: "string",
						enum: [component.name],
						description: `Artifact type - must be "${component.name}"`
					},
					base_selector: {
						type: "string",
						description: "JMESPath selector starting with \"result.\" to navigate to ONE specific item. Details selector will be relative to this selection. Use filtering to avoid arrays (e.g., \"result.items[?type=='guide']\")."
					},
					details_selector: enhancedSchema
				},
				required: [
					"id",
					"tool_call_id",
					"type",
					"base_selector"
				]
			};
			const normalizedPropsSchema = SchemaProcessor.makeAllPropertiesRequired(propsSchema);
			return {
				id: `artifact-create-${component.name.toLowerCase().replace(/\s+/g, "-")}`,
				tenantId,
				projectId,
				name: `ArtifactCreate_${component.name}`,
				description: `Create ${component.name} artifacts from tool results by extracting structured data using selectors.`,
				props: normalizedPropsSchema
			};
		});
	}
};

//#endregion
export { ArtifactCreateSchema, ArtifactReferenceSchema };