// Zod schemas keep all input validation in one place. Services and
// route handlers both import from here, so an API request and a
// programmatic call go through the same checks.

import { z } from 'zod';

// ------- auth -------
export const loginSchema = z.object({
  email: z.string().email().max(190),
  password: z.string().min(1).max(200),
});
export type LoginInput = z.infer<typeof loginSchema>;

// ------- categories -------
export const createCategorySchema = z.object({
  name: z.string().min(2).max(120).trim(),
});
export const updateCategorySchema = z.object({
  name: z.string().min(2).max(120).trim().optional(),
  isActive: z.boolean().optional(),
  sortOrder: z.number().int().min(0).optional(),
});
export type CreateCategoryInput = z.infer<typeof createCategorySchema>;
export type UpdateCategoryInput = z.infer<typeof updateCategorySchema>;

// ------- questions -------
export const createQuestionSchema = z.object({
  categoryId: z.number().int().positive(),
  productName: z.string().min(1).max(180).trim(),
  title: z.string().min(5).max(255).trim(),
  description: z.string().min(10).max(10000),
  imageUrl: z.string().url().max(500).optional().nullable(),
});
export type CreateQuestionInput = z.infer<typeof createQuestionSchema>;

// ------- answers -------
export const createAnswerSchema = z.object({
  questionId: z.number().int().positive(),
  answer: z.string().min(2).max(10000),
});
export type CreateAnswerInput = z.infer<typeof createAnswerSchema>;

// ------- users (admin) -------
export const createUserSchema = z.object({
  name: z.string().min(2).max(120),
  email: z.string().email().max(190),
  password: z.string().min(8).max(200),
  role: z.enum(['ADMIN', 'EMPLOYEE']).default('EMPLOYEE'),
});
export const updateUserSchema = z.object({
  name: z.string().min(2).max(120).optional(),
  role: z.enum(['ADMIN', 'EMPLOYEE']).optional(),
  password: z.string().min(8).max(200).optional(),
});
export type CreateUserInput = z.infer<typeof createUserSchema>;
export type UpdateUserInput = z.infer<typeof updateUserSchema>;
