/**
 * 刷新 Token 响应 DTO
 */
import {
  RefreshTokenResponseSchema,
  type RefreshTokenResponseInput,
  type RefreshTokenResponseData,
} from "@/data/schemas/auth/refresh_token_response";

export class RefreshTokenResponse {
  declare readonly token: string;
  declare readonly refreshToken: string;
  declare readonly userId: string;

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

  static from(input: RefreshTokenResponseInput): RefreshTokenResponse {
    return new RefreshTokenResponse(input);
  }

  static fromJson(json: unknown): RefreshTokenResponse {
    return RefreshTokenResponse.from(json as RefreshTokenResponseInput);
  }

  toJson(): RefreshTokenResponseData {
    return RefreshTokenResponseSchema.parse(this);
  }
}
