import { z } from 'zod';
import { createInsertSchema } from 'drizzle-zod';

import { tags } from '@/lib/db/schema/system';

// Derive the schema from the Drizzle table - adding a column to `tags`
// auto-includes it here; omitting / refining is per-field. Eliminates
// the validator-drift class of bugs the audit flagged.
export const createTagSchema = createInsertSchema(tags, {
  name: (s) => s.min(1).max(50),
  color: (s) => s.regex(/^#[0-9A-Fa-f]{6}$/, 'Color must be a valid hex color (e.g. #6B7280)'),
}).pick({ name: true, color: true });

export const updateTagSchema = createTagSchema.partial();

export type CreateTagInput = z.infer<typeof createTagSchema>;
export type UpdateTagInput = z.infer<typeof updateTagSchema>;
