import { z } from "zod";
import { buildPasswordSchema } from "@open-mercato/shared/lib/auth/passwordPolicy";
const passwordSchema = buildPasswordSchema();
const userLoginSchema = z.object({
  email: z.string().email(),
  password: z.string().min(6),
  requireRole: z.string().optional(),
  tenantId: z.string().uuid().optional()
});
const requestPasswordResetSchema = z.object({
  email: z.string().email()
});
const confirmPasswordResetSchema = z.object({
  token: z.string().min(10),
  password: passwordSchema
});
const refreshSessionRequestSchema = z.object({
  refreshToken: z.string().min(1)
});
const sidebarPreferencesScopeSchema = z.union([
  z.object({ type: z.literal("user") }),
  z.object({ type: z.literal("role"), roleId: z.string().uuid() })
]);
const sidebarVariantSettingsSchema = z.object({
  version: z.number().int().positive().optional(),
  groupOrder: z.array(z.string().min(1)).max(200).optional(),
  groupLabels: z.record(z.string().min(1), z.string().min(1).max(120)).optional(),
  itemLabels: z.record(z.string().min(1), z.string().min(1).max(120)).optional(),
  hiddenItems: z.array(z.string().min(1)).max(500).optional(),
  itemOrder: z.record(z.string().min(1), z.array(z.string().min(1)).max(500)).optional()
});
const createSidebarVariantInputSchema = z.object({
  name: z.string().trim().min(1).max(120).optional(),
  settings: sidebarVariantSettingsSchema.optional(),
  isActive: z.boolean().optional()
});
const updateSidebarVariantInputSchema = z.object({
  name: z.string().trim().min(1).max(120).optional(),
  settings: sidebarVariantSettingsSchema.optional(),
  isActive: z.boolean().optional()
});
const sidebarVariantRecordSchema = z.object({
  id: z.string().uuid(),
  name: z.string(),
  isActive: z.boolean(),
  settings: z.object({
    version: z.number().int().positive(),
    groupOrder: z.array(z.string()),
    groupLabels: z.record(z.string(), z.string()),
    itemLabels: z.record(z.string(), z.string()),
    hiddenItems: z.array(z.string()),
    itemOrder: z.record(z.string(), z.array(z.string()))
  }),
  createdAt: z.string(),
  updatedAt: z.string().nullable()
});
const sidebarPreferencesInputSchema = z.object({
  version: z.number().int().positive().optional(),
  groupOrder: z.array(z.string().min(1)).max(200).optional(),
  groupLabels: z.record(z.string().min(1), z.string().min(1).max(120)).optional(),
  itemLabels: z.record(z.string().min(1), z.string().min(1).max(120)).optional(),
  hiddenItems: z.array(z.string().min(1)).max(500).optional(),
  itemOrder: z.record(z.string().min(1), z.array(z.string().min(1)).max(500)).optional(),
  applyToRoles: z.array(z.string().uuid()).optional(),
  clearRoleIds: z.array(z.string().uuid()).optional(),
  scope: sidebarPreferencesScopeSchema.optional()
}).superRefine((value, ctx) => {
  const scopeType = value.scope?.type ?? "user";
  if (scopeType === "role") {
    if ((value.applyToRoles?.length ?? 0) > 0) {
      ctx.addIssue({
        code: z.ZodIssueCode.custom,
        path: ["applyToRoles"],
        message: 'applyToRoles is only valid when scope.type === "user"'
      });
    }
    if ((value.clearRoleIds?.length ?? 0) > 0) {
      ctx.addIssue({
        code: z.ZodIssueCode.custom,
        path: ["clearRoleIds"],
        message: 'clearRoleIds is only valid when scope.type === "user"'
      });
    }
  }
});
const userCreateSchema = z.object({
  email: z.string().email(),
  name: z.preprocess(
    (value) => {
      if (typeof value !== "string") return value;
      const trimmed = value.trim();
      return trimmed.length ? trimmed : void 0;
    },
    z.string().trim().min(1).max(120).optional()
  ),
  password: passwordSchema.optional(),
  sendInviteEmail: z.boolean().optional(),
  tenantId: z.string().uuid().optional(),
  organizationId: z.string().uuid(),
  rolesCsv: z.string().optional()
}).refine(
  (data) => data.password || data.sendInviteEmail,
  { message: "Either password or sendInviteEmail is required", path: ["password"] }
);
const featureCheckRequestSchema = z.object({
  features: z.array(z.string().max(128)).max(50).describe("Feature identifiers to check")
}).describe("Batch feature check payload");
export {
  confirmPasswordResetSchema,
  createSidebarVariantInputSchema,
  featureCheckRequestSchema,
  refreshSessionRequestSchema,
  requestPasswordResetSchema,
  sidebarPreferencesInputSchema,
  sidebarPreferencesScopeSchema,
  sidebarVariantRecordSchema,
  sidebarVariantSettingsSchema,
  updateSidebarVariantInputSchema,
  userCreateSchema,
  userLoginSchema
};
//# sourceMappingURL=validators.js.map
