/**
 * 头像数据 DTO
 */
import {
  AvatarDataSchema,
  type AvatarDataInput,
  type AvatarDataData,
} from "@/data/schemas/user/avatar_data";

export class AvatarData {
  declare readonly avatarUrl: string;
  declare readonly userId: string;

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

  static from(input: AvatarDataInput): AvatarData {
    return new AvatarData(input);
  }

  static fromJson(json: unknown): AvatarData {
    return AvatarData.from(json as AvatarDataInput);
  }

  toJson(): AvatarDataData {
    return AvatarDataSchema.parse(this);
  }
}
