import z from 'zod';

export const NotificationChannel = {
  NotSet: 0,
  Email: 1,
  SMS: 2,
  Phone: 4,
  Fax: 8,
  Postal: 16,
} as const;

const ALL_FLAGS = Object.values(NotificationChannel).reduce<number>(
  (a, b) => a | b,
  0,
);

export const NotificationChannelSchema = z
  .nativeEnum(NotificationChannel)
  .refine((val) => (val & ALL_FLAGS) === val, {
    message: 'Invalid notification channel',
  })
  .describe('Notification channel');

export type NotificationChannel = z.infer<typeof NotificationChannelSchema>;
