import define from "../../define.js";
import { Users, VerifiedBadgeRequests } from "../../../../models/index.js";
import { insertModerationLog } from "../../../../services/insert-moderation-log.js";
export const meta = {
    tags: [
        "admin"
    ],
    requireCredential: true,
    requireAdmin: true
};
export const paramDef = {
    type: "object",
    properties: {
        requestId: {
            type: "string",
            format: "misskey:id"
        },
        approve: {
            type: "boolean"
        }
    },
    required: [
        "requestId",
        "approve"
    ]
};
export default define(meta, paramDef, async (ps, me)=>{
    const request = await VerifiedBadgeRequests.findOneByOrFail({
        id: ps.requestId
    });
    if (request.status !== "pending") {
        throw new Error("request already resolved");
    }
    if (ps.approve) {
        await Users.update(request.userId, {
            isVerified: true
        });
    }
    await VerifiedBadgeRequests.update(request.id, {
        status: ps.approve ? "approved" : "rejected",
        resolvedAt: new Date(),
        resolverId: me.id
    });
    insertModerationLog(me, ps.approve ? "approveVerifiedBadgeRequest" : "rejectVerifiedBadgeRequest", {
        targetId: request.userId,
        requestId: request.id
    });
});
