import { FastifyRequest, FastifyReply } from "fastify";
import { setActivity, initRPC } from "./rp.service";

let initialized = false;

export function init() {
    if (!initialized) {
        initRPC(process.env.DISCORD_CLIENT_ID!);
        initialized = true;
    }
}

export async function setRPC(request: FastifyRequest, reply: FastifyReply) {
    const { details, state, mode } = request.body as {
        details?: string;
        state?: string;
        mode?: "watching" | "reading" | string;
    };

    setActivity({
        details,
        state,
        mode
    });

    return reply.send({ ok: true });
}