/**
 * Users DTOs with Zod Validation
 * Mecánicas Diesel - ERP Suite
 */

import { z } from 'zod';
import { UserRole } from '../auth/entities/user.entity';

// Create User Schema
export const createUserSchema = z.object({
  email: z.string().email('Email inválido'),
  password: z.string().min(8, 'La contraseña debe tener al menos 8 caracteres'),
  fullName: z.string().min(2, 'El nombre completo es requerido'),
  role: z.nativeEnum(UserRole, {
    errorMap: () => ({ message: 'Rol inválido' }),
  }),
  avatarUrl: z.string().url().optional(),
});

export type CreateUserDto = z.infer<typeof createUserSchema>;

// Update User Schema
export const updateUserSchema = z.object({
  fullName: z.string().min(2).optional(),
  role: z.nativeEnum(UserRole).optional(),
  isActive: z.boolean().optional(),
  avatarUrl: z.string().url().nullable().optional(),
});

export type UpdateUserDto = z.infer<typeof updateUserSchema>;

// Reset Password Schema
export const resetPasswordSchema = z.object({
  newPassword: z.string().min(8, 'La contraseña debe tener al menos 8 caracteres'),
});

export type ResetPasswordDto = z.infer<typeof resetPasswordSchema>;

// User Filters
export interface UserFilters {
  role?: UserRole;
  isActive?: boolean;
  search?: string;
}

// Pagination
export interface PaginationOptions {
  page: number;
  limit: number;
}

export interface PaginatedResult<T> {
  data: T[];
  total: number;
  page: number;
  limit: number;
  totalPages: number;
}
