import define from "../../../define.js";
import { ApiError } from "../../../error.js";
import { UserEmojis } from "../../../../../models/index.js";
import { clearUserEmojiCache } from "../../../../../misc/populate-emojis.js";
export const meta = {
    tags: [
        "account"
    ],
    requireCredential: true,
    kind: "write:account",
    errors: {
        noSuchEmoji: {
            message: "No such user emoji.",
            code: "NO_SUCH_USER_EMOJI",
            id: "a44ed453-7bec-4ae0-940e-2eb3e80e7b62"
        }
    }
};
export const paramDef = {
    type: "object",
    properties: {
        id: {
            type: "string",
            format: "misskey:id"
        }
    },
    required: [
        "id"
    ]
};
export default define(meta, paramDef, async (ps, me)=>{
    const emoji = await UserEmojis.findOneBy({
        id: ps.id,
        userId: me.id
    });
    if (!emoji) throw new ApiError(meta.errors.noSuchEmoji);
    await UserEmojis.delete(emoji.id);
    await clearUserEmojiCache(emoji.name, me.username, me.host);
});
