/**
 * 待同步的单条消息 DTO
 */
import {
  SyncMessageSchema,
  type SyncMessageInput,
  type SyncMessageData,
} from "@/data/schemas/chat/sync_message";

export class SyncMessage {
  declare readonly role: string;
  declare readonly content: string;
  declare readonly timestamp: string;

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

  static from(input: SyncMessageInput): SyncMessage {
    return new SyncMessage(input);
  }

  static fromJson(json: unknown): SyncMessage {
    return SyncMessage.from(json as SyncMessageInput);
  }

  toJson(): SyncMessageData {
    return SyncMessageSchema.parse(this);
  }
}
