import {
  TipPaymentPlanSchema,
  type TipPaymentPlanData,
  type TipPaymentPlanInput,
} from "@/data/schemas/payment/tip_payment_plan";

export class TipPaymentPlan {
  declare readonly planId: string;
  declare readonly planName: string;
  declare readonly amountCents: number;
  declare readonly currency: string;

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

  static from(input: TipPaymentPlanInput): TipPaymentPlan {
    return new TipPaymentPlan(input);
  }

  static fromJson(json: unknown): TipPaymentPlan {
    return TipPaymentPlan.from(json as TipPaymentPlanInput);
  }

  toJson(): TipPaymentPlanData {
    return TipPaymentPlanSchema.parse(this);
  }
}
