759481b621
Move request and response schemas into matching subdirectories, extract the shared chat lock type, and update barrels and imports without changing wire formats.
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
/**
|
|
* 支付套餐列表响应 DTO
|
|
*/
|
|
import {
|
|
PaymentPlansResponseSchema,
|
|
type FirstRechargeOfferData,
|
|
type PaymentPlansResponseData,
|
|
type PaymentPlansResponseInput,
|
|
} from "@/data/schemas/payment/response/payment_plans_response";
|
|
|
|
import { PaymentPlan } from "../payment_plan";
|
|
|
|
export class PaymentPlansResponse {
|
|
declare readonly isFirstRecharge: boolean;
|
|
declare readonly firstRechargeOffer: FirstRechargeOfferData | null;
|
|
declare readonly plans: PaymentPlan[];
|
|
|
|
private constructor(input: PaymentPlansResponseInput) {
|
|
const data = PaymentPlansResponseSchema.parse(input);
|
|
Object.assign(this, {
|
|
isFirstRecharge: data.isFirstRecharge,
|
|
firstRechargeOffer: data.firstRechargeOffer,
|
|
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 {
|
|
isFirstRecharge: this.isFirstRecharge,
|
|
firstRechargeOffer: this.firstRechargeOffer,
|
|
plans: this.plans.map((plan) => plan.toJson()),
|
|
};
|
|
}
|
|
}
|
|
|
|
export type FirstRechargeOffer = FirstRechargeOfferData;
|