import { kinds } from "nostr-tools";
import { map } from "rxjs";
import { getReplaceableIdentifier } from "../helpers/event.js";
import { getUserStatusPointer } from "../helpers/user-status.js";
/** A model that returns a parsed {@link UserStatus} for a certain type */
export function UserStatusModel(pubkey, type = "general") {
    return (events) => events.replaceable(kinds.UserStatuses, pubkey, type).pipe(map((event) => {
        if (!event)
            return undefined;
        const pointer = getUserStatusPointer(event);
        if (!pointer)
            return null;
        return {
            ...pointer,
            event,
            content: event.content,
        };
    }));
}
/** A model that returns a directory of parsed {@link UserStatus} for a pubkey */
export function UserStatusesModel(pubkey) {
    return (events) => events.timeline([{ kinds: [kinds.UserStatuses], authors: [pubkey] }]).pipe(map((events) => {
        return events.reduce((dir, event) => {
            try {
                const d = getReplaceableIdentifier(event);
                return { ...dir, [d]: { event, ...getUserStatusPointer(event), content: event.content } };
            }
            catch (error) {
                return dir;
            }
        }, {});
    }));
}
