/**
 * 创建支付订单响应 DTO
 */
import {
  CreatePaymentOrderResponseSchema,
  type CreatePaymentOrderResponseData,
  type CreatePaymentOrderResponseInput,
} from "@/data/schemas/payment/create_payment_order_response";

export class CreatePaymentOrderResponse {
  declare readonly orderId: string;
  declare readonly payParams: Record<string, unknown>;

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

  static from(
    input: CreatePaymentOrderResponseInput,
  ): CreatePaymentOrderResponse {
    return new CreatePaymentOrderResponse(input);
  }

  static fromJson(json: unknown): CreatePaymentOrderResponse {
    return CreatePaymentOrderResponse.from(
      json as CreatePaymentOrderResponseInput,
    );
  }

  toJson(): CreatePaymentOrderResponseData {
    return CreatePaymentOrderResponseSchema.parse(this);
  }
}
