import { z } from 'zod';

const LINK_TARGET_RE = /^[a-z0-9-]+\/[a-z0-9-]+:\S+$/;

export const CreatePromptSchema = z.object({
  name: z.string().min(1).max(100).regex(/^[a-z0-9-]+$/, 'Name must be lowercase alphanumeric with hyphens'),
  content: z.string().min(1).max(50000),
  projectId: z.string().optional(),
  priority: z.number().int().min(1).max(10).default(5).optional(),
  linkTarget: z.string().regex(LINK_TARGET_RE, 'Link target must be project/server:resource-uri').optional(),
});

export const UpdatePromptSchema = z.object({
  content: z.string().min(1).max(50000).optional(),
  priority: z.number().int().min(1).max(10).optional(),
  // linkTarget intentionally excluded — links are immutable
});

export const CreatePromptRequestSchema = z.object({
  name: z.string().min(1).max(100).regex(/^[a-z0-9-]+$/, 'Name must be lowercase alphanumeric with hyphens'),
  content: z.string().min(1).max(50000),
  projectId: z.string().optional(),
  priority: z.number().int().min(1).max(10).default(5).optional(),
  createdBySession: z.string().optional(),
  createdByUserId: z.string().optional(),
});

export const UpdatePromptRequestSchema = z.object({
  content: z.string().min(1).max(50000).optional(),
  priority: z.number().int().min(1).max(10).optional(),
});

export type CreatePromptInput = z.infer<typeof CreatePromptSchema>;
export type UpdatePromptInput = z.infer<typeof UpdatePromptSchema>;
export type CreatePromptRequestInput = z.infer<typeof CreatePromptRequestSchema>;
export type UpdatePromptRequestInput = z.infer<typeof UpdatePromptRequestSchema>;
