import { z } from 'zod';

/**
 * Payment Status enum
 * Zahlungsstatus
 */
export const PaymentStatus = {
  NotSet: 0,
  Open: 1,
  InProcess: 2,
  Paid: 4,
  Refunded: 8,
  PartiallyRefunded: 16,
  Cancelled: 32,
  Failed: 64,
  Pending: 128,
  Authorized: 256,
  Captured: 512,
  Voided: 1024,
} as const;

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

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

export type PaymentStatus = z.infer<typeof PaymentStatusSchema>;
