/**
 * 积分历史记录 DTO
 */
import {
  CreditsHistoryDataSchema,
  type CreditsHistoryDataInput,
  type CreditsHistoryDataData,
} from "@/data/schemas/user/credits_history_data";

export class CreditsHistoryData {
  declare readonly records: Record<string, unknown>[];
  declare readonly total: number;
  declare readonly limit: number;
  declare readonly offset: number;

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

  static from(input: CreditsHistoryDataInput): CreditsHistoryData {
    return new CreditsHistoryData(input);
  }

  static fromJson(json: unknown): CreditsHistoryData {
    return CreditsHistoryData.from(json as CreditsHistoryDataInput);
  }

  toJson(): CreditsHistoryDataData {
    return CreditsHistoryDataSchema.parse(this);
  }
}
