import { addChange, changeSchema } from "../../data/index.js";
import { authenticate } from "../authentication.js";
export async function addChangeRoutes(fastify) {
    const params = {
        type: "object",
        properties: {
            changeType: {
                type: "string",
            },
            targetType: {
                type: "string",
            },
            targetId: {
                type: "string",
            },
        },
        required: ["changeType", "targetType", "targetId"],
    };
    const response = {
        201: {
            description: "A new change",
            ...changeSchema.change,
        },
    };
    const schema = {
        description: "Add a new change",
        tags: ["change"],
        summary: "",
        body: changeSchema.changeData,
        response,
        params,
        security: [
            {
                apiKey: [],
            },
        ],
    };
    try {
        fastify.post("/:targetId", {
            schema,
            preHandler: authenticate(fastify),
            async handler(request, response) {
                const change = await addChange({
                    ...request.body,
                    type: request.params.changeType,
                    target: {
                        type: request.params.targetType,
                        id: request.params.targetId
                    }
                });
                response.status(201);
                response.send(change);
            },
        });
    }
    catch { }
}
//# sourceMappingURL=add-change.js.map