import { db } from "../../db/postgre.js";
import { Users } from "../index.js";
import { VerifiedBadgeRequest } from "../entities/verified-badge-request.js";
import { awaitAll } from "../../prelude/await-all.js";
export const VerifiedBadgeRequestRepository = db.getRepository(VerifiedBadgeRequest).extend({
    async pack (src) {
        const request = typeof src === "object" ? src : await this.findOneByOrFail({
            id: src
        });
        return await awaitAll({
            id: request.id,
            createdAt: request.createdAt.toISOString(),
            resolvedAt: request.resolvedAt?.toISOString() ?? null,
            status: request.status,
            comment: request.comment,
            userId: request.userId,
            resolverId: request.resolverId,
            user: Users.pack(request.user || request.userId, null, {
                detail: true
            }),
            resolver: request.resolverId ? Users.pack(request.resolver || request.resolverId, null, {
                detail: true
            }) : null
        });
    },
    packMany (requests) {
        return Promise.all(requests.map((x)=>this.pack(x)));
    }
});
