/**
 * 游客登录响应 DTO
 */
import {
  GuestLoginResponseSchema,
  type GuestLoginResponseInput,
  type GuestLoginResponseData,
} from "@/data/schemas/auth/guest_login_response";
import { User } from "@/data/dto/user/user";

export class GuestLoginResponse {
  declare readonly token: string;
  declare readonly deviceId: string;
  declare readonly userId: string;
  declare readonly isDeviceUser: boolean;
  declare readonly expiresIn: number;
  declare readonly user: User;

  private constructor(input: GuestLoginResponseInput) {
    const parsed = GuestLoginResponseSchema.parse(input);
    Object.assign(this, {
      ...parsed,
      user: parsed.user ? User.fromJson(parsed.user) : User.empty(),
    });
    Object.freeze(this);
  }

  static from(input: GuestLoginResponseInput): GuestLoginResponse {
    return new GuestLoginResponse(input);
  }

  static fromJson(json: unknown): GuestLoginResponse {
    return GuestLoginResponse.from(json as GuestLoginResponseInput);
  }

  toJson(): GuestLoginResponseData {
    const data = GuestLoginResponseSchema.parse(this);
    return data;
  }
}
