/**
 * Customer DTOs
 * Mecánicas Diesel - ERP Suite
 */

import { z } from 'zod';
import { CustomerType } from './entities/customer.entity';

// Create Customer DTO
export const CreateCustomerSchema = z.object({
  customerType: z.nativeEnum(CustomerType).default(CustomerType.INDIVIDUAL),
  name: z.string().min(2).max(200),
  legalName: z.string().max(300).optional(),
  rfc: z.string().max(13).optional(),
  email: z.string().email().optional(),
  phone: z.string().max(20).optional(),
  phoneSecondary: z.string().max(20).optional(),
  address: z.string().optional(),
  city: z.string().max(100).optional(),
  state: z.string().max(100).optional(),
  postalCode: z.string().max(10).optional(),
  creditDays: z.number().int().min(0).default(0),
  creditLimit: z.number().min(0).default(0),
  discountLaborPct: z.number().min(0).max(100).default(0),
  discountPartsPct: z.number().min(0).max(100).default(0),
  notes: z.string().optional(),
  preferredContact: z.enum(['phone', 'email', 'whatsapp']).default('phone'),
});

export type CreateCustomerDto = z.infer<typeof CreateCustomerSchema>;

// Update Customer DTO
export const UpdateCustomerSchema = CreateCustomerSchema.partial();
export type UpdateCustomerDto = z.infer<typeof UpdateCustomerSchema>;

// Customer Filters
export const CustomerFiltersSchema = z.object({
  customerType: z.nativeEnum(CustomerType).optional(),
  search: z.string().optional(),
  isActive: z.boolean().optional(),
  hasCredit: z.boolean().optional(),
  page: z.number().int().min(1).default(1),
  limit: z.number().int().min(1).max(100).default(20),
});

export type CustomerFilters = z.infer<typeof CustomerFiltersSchema>;
