/**
 * 登录响应 DTO
 */
import {
  LoginResponseSchema,
  type LoginResponseInput,
  type LoginResponseData,
} from "@/data/schemas/auth/login_response";
import { User } from "@/data/dto/user/user";

export class LoginResponse {
  declare readonly user: User;
  declare readonly token: string;
  declare readonly refreshToken: string;

  private constructor(input: LoginResponseInput) {
    const data = LoginResponseSchema.parse(input);
    Object.assign(this, {
      ...data,
      user: User.fromJson(data.user),
    });
    Object.freeze(this);
  }

  static from(input: LoginResponseInput): LoginResponse {
    return new LoginResponse(input);
  }

  static fromJson(json: unknown): LoginResponse {
    return LoginResponse.from(json as LoginResponseInput);
  }

  toJson(): LoginResponseData {
    return LoginResponseSchema.parse(this);
  }
}
