/*
 * Copyright (C) 2025-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;

import com.google.gson.annotations.SerializedName;

import java.util.List;

/**
 * Class representing the server's configuration
 */
public class ServerConfig {

    /**
     * Class representing the database section of the server configuration
     *
     * @param type        The database type
     * @param host        The database host
     * @param name        The database name
     * @param username    The username to use for connecting to the database
     * @param password    The password to use for connecting to the database
     * @param autoupgrade True if automatic database upgrades should be performed on startup
     */
    public record Database(String type, String host, String name, String username, String password,
                           boolean autoupgrade) {
    }

    /**
     * Listener types
     */
    public enum ListenerType {
        @SerializedName("tcp")
        TCP,
        @SerializedName("unix")
        UNIX
    }

    /**
     * Class representing the SSL configuration of the listener section
     *
     * @param enabled        True if SSL should be enabled for this listener
     * @param certificate    The path to fullchain.pem
     * @param certificateKey The path to privkey.pem
     */
    public record SSL(boolean enabled, String certificate, String certificateKey) {
    }

    /**
     * Class representing the listener section of the server configuration
     *
     * @param type The {@link ListenerType}
     * @param host The host to listen on (for tcp sockets)
     * @param port The port to listen on (for tcp sockets)
     * @param path The path to listen on (for unix sockets)
     * @param ssl  The SSL configuration
     */
    public record Listener(ListenerType type, String host, int port, String path, SSL ssl) {
    }

    /**
     * The listener configuration
     */
    public List<Listener> listeners = List.of(new Listener(ListenerType.TCP, "::", 8080, null, null));
    /**
     * The database connection configuration
     */
    public Database database = new Database("mysql", "localhost", "aglais_zms",
            "aglais", "aglais", true);
    /**
     * Proxies to trust for setting the X-Real-IP header
     */
    public List<String> trustedProxies = List.of("0:0:0:0:0:0:0:1", "127.0.0.1");
}
