/**
 * 发送验证码请求 DTO
 */
import {
  SendCodeRequestSchema,
  type SendCodeRequestInput,
  type SendCodeRequestData,
} from "@/data/schemas/auth/send_code_request";

export class SendCodeRequest {
  declare readonly email: string;

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

  static from(input: SendCodeRequestInput): SendCodeRequest {
    return new SendCodeRequest(input);
  }

  static fromJson(json: unknown): SendCodeRequest {
    return SendCodeRequest.from(json as SendCodeRequestInput);
  }

  toJson(): SendCodeRequestData {
    return SendCodeRequestSchema.parse(this);
  }
}
