/**
 * 发送消息响应 DTO
 */
import {
  ChatSendResponseSchema,
  type ChatSendResponseInput,
  type ChatSendResponseData,
  type ChatImageData,
  type ChatLockDetailData,
} from "@/data/schemas/chat";

export class ChatSendResponse {
  declare readonly reply: string;
  declare readonly audioUrl: string;
  declare readonly messageId: string;
  declare readonly isGuest: boolean;
  declare readonly timestamp: number;
  declare readonly image: ChatImageData;
  declare readonly lockDetail: ChatLockDetailData;
  declare readonly canSendMessage: boolean;
  declare readonly cannotSendReason: string | null;
  declare readonly creditBalance: number;
  declare readonly creditsCharged: number;
  declare readonly requiredCredits: number;
  declare readonly shortfallCredits: number;

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

  static from(input: ChatSendResponseInput): ChatSendResponse {
    return new ChatSendResponse(input);
  }

  static fromJson(json: unknown): ChatSendResponse {
    return ChatSendResponse.from(json as ChatSendResponseInput);
  }

  toJson(): ChatSendResponseData {
    return ChatSendResponseSchema.parse(this);
  }
}
