/**
 * 发送消息请求 DTO
 */
import {
  SendMessageRequestSchema,
  type SendMessageRequestInput,
  type SendMessageRequestData,
} from "@/data/schemas/chat/send_message_request";

export class SendMessageRequest {
  declare readonly message: string;
  declare readonly image: string;
  declare readonly imageId: string;
  declare readonly imageThumbUrl: string;
  declare readonly imageMediumUrl: string;
  declare readonly imageOriginalUrl: string;
  declare readonly imageWidth: number;
  declare readonly imageHeight: number;
  declare readonly useWebSocket: boolean;

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

  static from(input: SendMessageRequestInput): SendMessageRequest {
    return new SendMessageRequest(input);
  }

  static fromJson(json: unknown): SendMessageRequest {
    return SendMessageRequest.from(json as SendMessageRequestInput);
  }

  toJson(): SendMessageRequestData {
    return SendMessageRequestSchema.parse(this);
  }
}
