/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2025 SteamWar.de-Serverteam
 *
 *   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 <https://www.gnu.org/licenses/>.
 */

package de.steamwar.velocitycore.discord;

import de.steamwar.velocitycore.Config;
import de.steamwar.velocitycore.VelocityCore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;

import java.io.File;
import java.util.List;
import java.util.Map;

@Getter
public class DiscordConfig {

    public static DiscordConfig load() {
        File file = new File(System.getProperty("user.home"), "discord.yml");
        if(!file.exists() || VelocityCore.get().getConfig().isEventmode())
            return null;

        return Config.load(DiscordConfig.class, file, description -> description.addPropertyParameters("roles", String.class, DiscordRole.class));
    }

    public String channel(String type) {
        return channels.get(type);
    }

    private String token;
    private String guild;

    private Map<String, String> channels;
    private Map<String, String> ranks;
    private Map<String, DiscordRole> roles;
    private List<String> rules;

    private String ticketcategory;

    private Map<String, String> councilThread;

    @NoArgsConstructor
    public static class DiscordRole {

        private String emoji;
        private String label;
        private String roleId;

        public Button toButton() {
            return Button.of(ButtonStyle.SECONDARY, roleId, label, Emoji.fromUnicode(emoji));
        }
    }
}
