import * as z from 'zod';

export const customerSchema = z.object({
  name: z.string().min(2, 'Customer name must be at least 2 characters'),
  abbr: z.string().optional(),
  taxId: z.string().optional(),
  customerType: z.string().min(1, 'Please select a customer type'),
  customerStatus: z.string().min(1, 'Please select a customer status'),
  branchId: z.string().optional().nullable(),
  address: z.string().optional(),
  province: z.string().optional(),
  district: z.string().optional(),
  subDistrict: z.string().optional(),
  postalCode: z.string().optional(),
  country: z.string().optional(),
  phone: z.string().optional(),
  fax: z.string().optional(),
  email: z
    .string()
    .optional()
    .refine((value) => !value || z.email().safeParse(value).success, 'Please enter a valid email'),
  website: z.string().optional(),
  leadChannel: z.string().optional().nullable(),
  customerGroup: z.string().optional().nullable(),
  customerSubGroup: z.string().optional().nullable(),
  notes: z.string().optional(),
  isActive: z.boolean().default(true)
});

export const customerContactSchema = z.object({
  name: z.string().min(2, 'Contact name must be at least 2 characters'),
  position: z.string().optional(),
  department: z.string().optional(),
  phone: z.string().optional(),
  mobile: z.string().optional(),
  email: z
    .string()
    .optional()
    .refine((value) => !value || z.email().safeParse(value).success, 'Please enter a valid email'),
  isPrimary: z.boolean().default(false),
  notes: z.string().optional(),
  isActive: z.boolean().default(true)
});

export type CustomerFormValues = z.input<typeof customerSchema>;
export type CustomerContactFormValues = z.input<typeof customerContactSchema>;
