/**
 * 创建支付订单请求 DTO
 */
import {
  CreatePaymentOrderRequestSchema,
  type CreatePaymentOrderRequestData,
  type CreatePaymentOrderRequestInput,
  type PayChannel,
} from "@/data/schemas/payment/create_payment_order_request";

export type { PayChannel };

export class CreatePaymentOrderRequest {
  declare readonly planId: string;
  declare readonly payChannel: PayChannel;
  declare readonly autoRenew: boolean;

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

  static from(
    input: CreatePaymentOrderRequestInput,
  ): CreatePaymentOrderRequest {
    return new CreatePaymentOrderRequest(input);
  }

  static fromJson(json: unknown): CreatePaymentOrderRequest {
    return CreatePaymentOrderRequest.from(
      json as CreatePaymentOrderRequestInput,
    );
  }

  toJson(): CreatePaymentOrderRequestData {
    return CreatePaymentOrderRequestSchema.parse(this);
  }
}
