/**
 * 支付 WebSocket 事件
 */
import { z } from "zod";

export const PaymentSuccessVipEventSchema = z.object({
  type: z.literal("payment_success"),
  orderId: z.string(),
  payType: z.literal("vip"),
  planName: z.string(),
  vipExpiresAt: z.string().nullable(),
});

export const PaymentSuccessDolEventSchema = z.object({
  type: z.literal("payment_success"),
  orderId: z.string(),
  payType: z.literal("dol"),
  planName: z.string(),
  dolAmount: z.number(),
  dolBalance: z.number(),
});

export const PaymentFailedEventSchema = z.object({
  type: z.literal("payment_failed"),
  orderId: z.string(),
  info: z.string(),
});

export const PaymentSuccessEventSchema = z.discriminatedUnion("payType", [
  PaymentSuccessVipEventSchema,
  PaymentSuccessDolEventSchema,
]);

export const PaymentWebSocketEventSchema = z.union([
  PaymentSuccessEventSchema,
  PaymentFailedEventSchema,
]);

export type PaymentSuccessVipEventData = z.output<
  typeof PaymentSuccessVipEventSchema
>;
export type PaymentSuccessDolEventData = z.output<
  typeof PaymentSuccessDolEventSchema
>;
export type PaymentFailedEventData = z.output<typeof PaymentFailedEventSchema>;
export type PaymentSuccessEventData = z.output<typeof PaymentSuccessEventSchema>;
export type PaymentWebSocketEventInput = z.input<
  typeof PaymentWebSocketEventSchema
>;
export type PaymentWebSocketEventData = z.output<
  typeof PaymentWebSocketEventSchema
>;
