/**
 * 支付 WebSocket 事件 DTO
 */
import {
  PaymentWebSocketEventSchema,
  type PaymentWebSocketEventData,
  type PaymentWebSocketEventInput,
} from "@/data/schemas/payment/payment_websocket_event";

export class PaymentWebSocketEvent {
  declare readonly type: PaymentWebSocketEventData["type"];
  declare readonly orderId: string;

  private constructor(input: PaymentWebSocketEventInput) {
    const data = PaymentWebSocketEventSchema.parse(input);
    Object.assign(this, data);
    Object.freeze(this);
  }

  static from(input: PaymentWebSocketEventInput): PaymentWebSocketEvent {
    return new PaymentWebSocketEvent(input);
  }

  static fromJson(json: unknown): PaymentWebSocketEvent {
    return PaymentWebSocketEvent.from(json as PaymentWebSocketEventInput);
  }

  toJson(): PaymentWebSocketEventData {
    return PaymentWebSocketEventSchema.parse(this);
  }
}

export type { PaymentWebSocketEventData };
