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

//#region src/validation/dolt-schemas.ts
const BranchNameSchema = z.string().min(1, "Branch name cannot be empty").max(255, "Branch name too long").regex(/^[a-zA-Z0-9\-_./]+$/, { message: "Branch name can only contain letters, numbers, hyphens, underscores, dots, and slashes" }).openapi({
	example: "feature-x",
	description: "Name of the branch"
});
const CreateBranchRequestSchema = z.object({
	name: BranchNameSchema,
	fromBranch: z.string().optional().describe("Branch name to create from. Defaults to tenant main branch."),
	fromCommit: z.string().optional().describe("Commit hash to create from. Mutually exclusive with fromBranch.")
}).openapi("CreateBranchRequest");
const BranchInfoSchema = z.object({
	baseName: z.string().describe("User-provided branch name"),
	fullName: z.string().describe("Full namespaced branch name"),
	hash: z.string().describe("Current commit hash of the branch")
}).openapi("BranchInfo");
const BranchResponseSchema = z.object({ data: BranchInfoSchema }).openapi("BranchResponse");
const BranchListResponseSchema = z.object({ data: z.array(BranchInfoSchema) }).openapi("BranchListResponse");
const BranchNameParamsSchema = z.object({
	tenantId: z.string().openapi({ param: {
		name: "tenantId",
		in: "path"
	} }),
	projectId: z.string().openapi({ param: {
		name: "projectId",
		in: "path"
	} }),
	branchName: z.string().openapi({ param: {
		name: "branchName",
		in: "path"
	} })
}).openapi("BranchNameParams");
const ResolvedRefSchema = z.object({
	type: z.enum([
		"commit",
		"tag",
		"branch"
	]).describe("The type of ref"),
	name: z.string().describe("The name of the ref (branch name, tag name, or commit hash)"),
	hash: z.string().describe("The commit hash this ref resolves to")
}).openapi("ResolvedRef");
const ConflictResolutionSchema = z.object({
	table: z.string(),
	primaryKey: z.record(z.string(), z.string()),
	rowDefaultPick: z.enum(["ours", "theirs"]),
	columns: z.record(z.string(), z.enum(["ours", "theirs"])).optional()
});
const DiffSummaryItemSchema = z.object({
	table: z.string(),
	diffType: z.string(),
	dataChange: z.boolean(),
	schemaChange: z.boolean()
}).openapi("DiffSummaryItem");
const ConflictItemSchema = z.object({
	table: z.string(),
	primaryKey: z.record(z.string(), z.string()),
	ourDiffType: z.string(),
	theirDiffType: z.string(),
	base: z.record(z.string(), z.unknown()).nullable(),
	ours: z.record(z.string(), z.unknown()).nullable(),
	theirs: z.record(z.string(), z.unknown()).nullable()
}).openapi("ConflictItem");
const MergePreviewRequestSchema = z.object({
	sourceBranch: z.string(),
	targetBranch: z.string()
}).openapi("MergePreviewRequest");
const MergePreviewResponseSchema = z.object({ data: z.object({
	hasConflicts: z.boolean(),
	sourceHash: z.string(),
	targetHash: z.string(),
	canFastForward: z.boolean(),
	diffSummary: z.array(DiffSummaryItemSchema),
	conflicts: z.array(ConflictItemSchema)
}) }).openapi("MergePreviewResponse");
const MergeExecuteRequestSchema = z.object({
	sourceBranch: z.string(),
	targetBranch: z.string(),
	sourceHash: z.string(),
	targetHash: z.string(),
	message: z.string().optional(),
	author: z.object({
		name: z.string(),
		email: z.string()
	}).optional(),
	resolutions: z.array(ConflictResolutionSchema).optional()
}).openapi("MergeExecuteRequest");
const MergeExecuteResponseSchema = z.object({ data: z.object({
	status: z.literal("success"),
	mergeCommitHash: z.string(),
	sourceBranch: z.string(),
	targetBranch: z.string()
}) }).openapi("MergeExecuteResponse");

//#endregion
export { BranchInfoSchema, BranchListResponseSchema, BranchNameParamsSchema, BranchNameSchema, BranchResponseSchema, ConflictItemSchema, ConflictResolutionSchema, CreateBranchRequestSchema, DiffSummaryItemSchema, MergeExecuteRequestSchema, MergeExecuteResponseSchema, MergePreviewRequestSchema, MergePreviewResponseSchema, ResolvedRefSchema };