/**
 * 支付套餐列表响应 DTO
 */
import {
  PaymentPlansResponseSchema,
  type PaymentPlansResponseData,
  type PaymentPlansResponseInput,
} from "@/data/schemas/payment/payment_plans_response";

import { PaymentPlan } from "./payment_plan";

export class PaymentPlansResponse {
  declare readonly plans: PaymentPlan[];

  private constructor(input: PaymentPlansResponseInput) {
    const data = PaymentPlansResponseSchema.parse(input);
    Object.assign(this, {
      plans: data.plans.map((plan) => PaymentPlan.from(plan)),
    });
    Object.freeze(this);
  }

  static from(input: PaymentPlansResponseInput): PaymentPlansResponse {
    return new PaymentPlansResponse(input);
  }

  static fromJson(json: unknown): PaymentPlansResponse {
    return PaymentPlansResponse.from(json as PaymentPlansResponseInput);
  }

  toJson(): PaymentPlansResponseData {
    return {
      plans: this.plans.map((plan) => plan.toJson()),
    };
  }
}
