/**
 * 支付套餐 DTO
 */
import {
  PaymentPlanSchema,
  type PaymentPlanData,
  type PaymentPlanInput,
} from "@/data/schemas/payment/payment_plan";

export class PaymentPlan {
  declare readonly planId: string;
  declare readonly planName: string;
  declare readonly orderType: string;
  declare readonly vipDays: number | null;
  declare readonly dolAmount: number | null;
  declare readonly creditBalance: number;
  declare readonly amountCents: number;
  declare readonly originalAmountCents: number | null;
  declare readonly dailyPriceCents: number | null;
  declare readonly currency: string;

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

  static from(input: PaymentPlanInput): PaymentPlan {
    return new PaymentPlan(input);
  }

  static fromJson(json: unknown): PaymentPlan {
    return PaymentPlan.from(json as PaymentPlanInput);
  }

  toJson(): PaymentPlanData {
    return PaymentPlanSchema.parse(this);
  }
}
