import { config } from '@opengis/fastify-table/utils.js';

import mapnik from '../../../plugins/mapnik/funcs/mapnik.js';

const { GetStat } = mapnik();

export default async function mapnikStat({
    params, query,
}, reply) {
    if (!config.mapServerAddress) {
        return reply.status(400).send({ error: 'mapnik server address needed', code: 400 });
    }

    const stat = await GetStat({
        period: params.period,
        ttl: query.nocache ? '0' : undefined,
    });

    return reply.status(200).send(stat);
}
