/**
 * 最近记忆 DTO
 */
import {
  RecentMemorySchema,
  type RecentMemoryInput,
  type RecentMemoryData,
} from "@/data/schemas/user/recent_memory";

export class RecentMemory {
  declare readonly type: string;
  declare readonly content: string;
  declare readonly importance: number;
  declare readonly createdAt: string;

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

  static from(input: RecentMemoryInput): RecentMemory {
    return new RecentMemory(input);
  }

  static fromJson(json: unknown): RecentMemory {
    return RecentMemory.from(json as RecentMemoryInput);
  }

  toJson(): RecentMemoryData {
    return RecentMemorySchema.parse(this);
  }
}
