import { z } from 'zod';

const CHANNELS = ['email', 'phone', 'whatsapp', 'in_person', 'video', 'other'] as const;
const DIRECTIONS = ['outbound', 'inbound'] as const;

/** Cap summary length so a rep can't accidentally paste a 10MB email body. */
const SUMMARY_MAX = 4000;

export const createContactLogSchema = z.object({
  occurredAt: z.coerce.date(),
  channel: z.enum(CHANNELS),
  direction: z.enum(DIRECTIONS).default('outbound'),
  summary: z.string().min(1).max(SUMMARY_MAX),
  followUpAt: z.coerce.date().optional().nullable(),
});

export const updateContactLogSchema = z
  .object({
    occurredAt: z.coerce.date(),
    channel: z.enum(CHANNELS),
    direction: z.enum(DIRECTIONS),
    summary: z.string().min(1).max(SUMMARY_MAX),
    followUpAt: z.coerce.date().nullable(),
  })
  .partial();

export type CreateContactLogPayload = z.infer<typeof createContactLogSchema>;
export type UpdateContactLogPayload = z.infer<typeof updateContactLogSchema>;
