import { z } from 'zod';

/**
 * Order Item Type enum
 * Bestellposten-Typ
 */
export const OrderItemType = {
  NotSet: 0,
  Single: 1,
  Head: 2,
  Child: 4,
  Service: 8,
  Discount: 16,
  Shipping: 32,
  Gift: 64,
  Return: 256,
  Cancellation: 512,
  Replacement: 1024,
} as const;

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

export const OrderItemTypeSchema = z
  .nativeEnum(OrderItemType)
  .refine((val) => (val & ALL_FLAGS) === val, {
    message: 'Invalid order item type',
  })
  .describe('Order item type');

export type OrderItemType = z.infer<typeof OrderItemTypeSchema>;
