import { z } from 'zod';

/** CM-1: client groups (mailing/segment lists). */

export const createClientGroupSchema = z.object({
  name: z.string().trim().min(1, 'Group name is required').max(120),
  description: z.string().trim().max(2000).nullish(),
  color: z
    .string()
    .regex(/^#[0-9a-fA-F]{6}$/, 'Color must be a hex value like #6B7280')
    .optional(),
  /** Mailchimp tag/segment name this group maps to. Null until wired up. */
  mailchimpTag: z.string().trim().max(200).nullish(),
});

export const updateClientGroupSchema = createClientGroupSchema.partial();

/** Wipe-and-rewrite the group's membership to exactly this set of clients. */
export const setGroupMembersSchema = z.object({
  clientIds: z.array(z.string().min(1)).max(5000),
});

export type CreateClientGroupInput = z.infer<typeof createClientGroupSchema>;
export type UpdateClientGroupInput = z.infer<typeof updateClientGroupSchema>;
export type SetGroupMembersInput = z.infer<typeof setGroupMembersSchema>;
