/**
 * 积分数据 DTO
 */
import {
  CreditsDataSchema,
  type CreditsDataInput,
  type CreditsDataData,
} from "@/data/schemas/user/credits_data";

export class CreditsData {
  declare readonly userId: string;
  declare readonly dolBalance: number;

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

  static from(input: CreditsDataInput): CreditsData {
    return new CreditsData(input);
  }

  static fromJson(json: unknown): CreditsData {
    return CreditsData.from(json as CreditsDataInput);
  }

  toJson(): CreditsDataData {
    return CreditsDataSchema.parse(this);
  }
}
