/*
 * Copyright (C) 2026  Tim Zimmermann <tim@aglais.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.aglais.zms.server.route;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpRequest;
import org.aglais.zms.server.AglaisHttpAuthenticator;
import org.aglais.zms.server.routing.HttpRoute;

import static org.aglais.zms.api.core.APIConstants.*;
import static org.aglais.zms.server.route.util.RouteUtil.writeJson;

/**
 * Route handler for /api/* endpoints
 */
public class ApiRoute {

    @HttpRoute(path = URL_API_HEALTH_CHECK)
    public void healthCheck(ChannelHandlerContext ctx, HttpRequest request, FullHttpResponse response) {
        writeJson(response.content(), API_HEALTH_CHECK_MAGIC);
    }

    @HttpRoute(path = URL_API_VERSION_CURRENT)
    public void versionCurrent(ChannelHandlerContext ctx, HttpRequest request, FullHttpResponse response) {
        writeJson(response.content(), API_VERSION_CURRENT);
    }

    @HttpRoute(path = URL_API_VERSION_MIN)
    public void versionMin(ChannelHandlerContext ctx, HttpRequest request, FullHttpResponse response) {
        writeJson(response.content(), API_VERSION_MIN);
    }

    @HttpRoute(path = URL_API_USER_SELF)
    public void userSelf(ChannelHandlerContext ctx, HttpRequest request, FullHttpResponse response) {
        writeJson(response.content(), ctx.channel().attr(AglaisHttpAuthenticator.USER_KEY).get());
    }

}
