2025-07-07 03:42:35 +02:00
|
|
|
import type { z } from "zod/v4";
|
2025-04-08 16:01:10 +02:00
|
|
|
import { UserSchema } from "../schemas/user.ts";
|
|
|
|
|
import type { JSONObject } from "../types.ts";
|
|
|
|
|
import { ImageContentFormat, TextContentFormat } from "./contentformat.ts";
|
|
|
|
|
import { Entity } from "./entity.ts";
|
|
|
|
|
|
|
|
|
|
export class User extends Entity {
|
2025-05-23 17:29:27 +02:00
|
|
|
public static override name = "User";
|
2025-04-08 16:01:10 +02:00
|
|
|
|
2025-05-23 17:29:27 +02:00
|
|
|
public constructor(public override data: z.infer<typeof UserSchema>) {
|
2025-04-08 16:01:10 +02:00
|
|
|
super(data);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-23 17:29:27 +02:00
|
|
|
public static override fromJSON(json: JSONObject): Promise<User> {
|
2025-04-08 16:01:10 +02:00
|
|
|
return UserSchema.parseAsync(json).then((u) => new User(u));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public get avatar(): ImageContentFormat | undefined {
|
|
|
|
|
return this.data.avatar
|
|
|
|
|
? new ImageContentFormat(this.data.avatar)
|
|
|
|
|
: undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public get header(): ImageContentFormat | undefined {
|
|
|
|
|
return this.data.header
|
|
|
|
|
? new ImageContentFormat(this.data.header)
|
|
|
|
|
: undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public get bio(): TextContentFormat | undefined {
|
|
|
|
|
return this.data.bio ? new TextContentFormat(this.data.bio) : undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|