import { z } from 'zod';

/**
 * Payment Type enum
 * Zahlungsart
 */
export const PaymentType = {
  NotSet: 0,
  Cash: 1,
  Card: 2,
  Invoice: 4,
  DirectDebit: 8,
  PayPal: 16,
  CreditCard: 32,
  DebitCard: 64,
  BankTransfer: 128,
  Prepayment: 256,
  OnAccount: 512,
  GiftCard: 1024,
  Voucher: 2048,
  Financing: 4096,
  ApplePay: 8192,
  GooglePay: 16384,
  AmazonPay: 32768,
} as const;

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

export const PaymentTypeSchema = z
  .nativeEnum(PaymentType)
  .refine((val) => (val & ALL_FLAGS) === val, {
    message: 'Invalid payment type',
  })
  .describe('Payment type');

export type PaymentType = z.infer<typeof PaymentTypeSchema>;
