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

//#region src/validation/schemas/shared.ts
const MIN_ID_LENGTH = 1;
const MAX_ID_LENGTH = 255;
const URL_SAFE_ID_PATTERN = /^[a-zA-Z0-9\-_.]+$/;
const PROJECT_ID_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
const ResourceIdSchema = z.string().trim().nonempty("Id is required").max(MAX_ID_LENGTH).regex(URL_SAFE_ID_PATTERN, { message: "ID must contain only letters, numbers, hyphens, underscores, and dots" }).refine((value) => value !== "new", "Must not use a reserved name \"new\"").openapi("ResourceId", {
	description: "Resource identifier",
	example: "resource_789"
});
const ProjectResourceIdSchema = z.string().trim().nonempty("Id is required").max(MAX_ID_LENGTH).regex(PROJECT_ID_PATTERN, { message: "Project ID must start and end with lowercase alphanumeric characters, and may contain hyphens" }).openapi("ProjectResourceId", {
	description: "Project identifier (lowercase alphanumeric and hyphens only)",
	example: "my-project-123"
});
const StringRecordSchema = z.record(z.string(), z.string("All object values must be strings"), "Must be valid JSON object").openapi("StringRecord");
const pageNumber = z.coerce.number().min(1).default(1).openapi("PaginationPageQueryParam");
const limitNumber = z.coerce.number().min(1).max(100).default(10).openapi("PaginationLimitQueryParam");
const PaginationSchema = z.object({
	page: pageNumber,
	limit: limitNumber,
	total: z.number(),
	pages: z.number(),
	completedCount: z.number().optional()
}).openapi("Pagination");
const PaginationQueryParamsSchema = z.object({
	page: pageNumber,
	limit: limitNumber
}).openapi("PaginationQueryParams");
const omitTenantScope = (schema) => schema.omit({ tenantId: true });
const omitTimestamps = (schema) => schema.omit({
	createdAt: true,
	updatedAt: true
});
const omitGeneratedFields = (schema) => schema.omit({
	id: true,
	createdAt: true,
	updatedAt: true
});
const createApiSchema = (schema) => schema.omit({
	tenantId: true,
	projectId: true
});
const createApiInsertSchema = (schema) => schema.omit({
	tenantId: true,
	projectId: true
});
const createApiUpdateSchema = (schema) => schema.omit({
	tenantId: true,
	projectId: true
}).partial();
const createAgentScopedApiSchema = (schema) => schema.omit({
	tenantId: true,
	projectId: true,
	agentId: true
});
const createAgentScopedApiInsertSchema = (schema) => schema.omit({
	tenantId: true,
	projectId: true,
	agentId: true
});
const createAgentScopedApiUpdateSchema = (schema) => schema.omit({
	tenantId: true,
	projectId: true,
	agentId: true
}).partial();

//#endregion
export { MAX_ID_LENGTH, MIN_ID_LENGTH, PROJECT_ID_PATTERN, PaginationQueryParamsSchema, PaginationSchema, ProjectResourceIdSchema, ResourceIdSchema, StringRecordSchema, URL_SAFE_ID_PATTERN, createAgentScopedApiInsertSchema, createAgentScopedApiSchema, createAgentScopedApiUpdateSchema, createApiInsertSchema, createApiSchema, createApiUpdateSchema, omitGeneratedFields, omitTenantScope, omitTimestamps };