import { z } from 'zod';

export const AllergeneType = {
  NotSet: 0,
  SulfurDioxide: 1,
  EggWhite: 2,
  EggYolk: 4,
  Egg: 6,
  Shellfish: 8,
  Fish: 16,
  Mollusc: 32,
  Celery: 64,
  Mustard: 128,
  Sesame: 256,
  MilkProtein: 512,
  Lactose: 1024,
  Milk: 1536,
  Nuts: 2048,
  Hazelnut: 6144,
  Almond: 10240,
  Walnut: 18432,
  Cashew: 34816,
  Pecan: 67584,
  BrazilNut: 133120,
  Pistachio: 264192,
  Macadamia: 526336,
  Gluten: 1048576,
  Wheat: 3145728,
  Rye: 5242880,
  Oat: 9437184,
  Barley: 17825792,
  Spelt: 34603008,
  Kamut: 68157440,
  Emmer: 135266304,
  Pulse: 268435456,
  Peanuts: 805306368,
  Soy: 1342177280,
  Chickpea: 2415919104,
  Lentil: 4563402752,
  Peavine: 8858370048,
  Lupin: 17448304640,
  Pea: 34628173824,
  Bean: 68987912192,
  Cinnamon: 137438953472,
} as const;

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

export const AllergeneTypeSchema = z
  .nativeEnum(AllergeneType)
  .refine(
    (val) => (val & ~ALL_FLAGS) === 0,
    () => ({ message: 'Invalid allergene type combination' }),
  )
  .describe('Allergen type classification for food items');

export type AllergeneType = z.infer<typeof AllergeneTypeSchema>;
