package me.StevenLawson.TotalFreedomMod.discord.sender;

import me.StevenLawson.TotalFreedomMod.discord.bridge.DiscordBridge;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissibleBase;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import org.javacord.api.entity.user.User;

import java.util.Set;

public class DiscordCommandSender implements CommandSender {
    private final User user;
    private final org.javacord.api.entity.server.Server server;
    protected final PermissibleBase perm;

    public DiscordCommandSender(User user, org.javacord.api.entity.server.Server server) {
        this.user = user;
        this.server = server;
        this.perm = new PermissibleBase(this);
    }

    @Override
    public void sendMessage(String s) {
        user.sendMessage(DiscordBridge.sanitizeMessage(s));
    }

    @Override
    public void sendMessage(String[] strings) {
        user.sendMessage(DiscordBridge.sanitizeMessage(String.join("\n", strings)));
    }

    @Override
    public Server getServer() {
        return Bukkit.getServer();
    }

    @Override
    public String getName() {
        return user.getDiscriminatedName();
    }

    @Override
    public boolean isPermissionSet(String s) {
        return this.perm.isPermissionSet(s);
    }

    @Override
    public boolean isPermissionSet(Permission permission) {
        return this.perm.isPermissionSet(permission);
    }

    @Override
    public boolean hasPermission(String s) {
        return this.perm.hasPermission(s);
    }

    @Override
    public boolean hasPermission(Permission permission) {
        return this.perm.hasPermission(permission);
    }

    @Override
    public PermissionAttachment addAttachment(Plugin plugin, String s, boolean b) {
        return this.perm.addAttachment(plugin, s, b);
    }

    @Override
    public PermissionAttachment addAttachment(Plugin plugin) {
        return this.perm.addAttachment(plugin);
    }

    @Override
    public PermissionAttachment addAttachment(Plugin plugin, String s, boolean b, int i) {
        return this.perm.addAttachment(plugin, s, b, i);
    }

    @Override
    public PermissionAttachment addAttachment(Plugin plugin, int i) {
        return this.perm.addAttachment(plugin, i);
    }

    @Override
    public void removeAttachment(PermissionAttachment permissionAttachment) {
        this.perm.removeAttachment(permissionAttachment);
    }

    @Override
    public void recalculatePermissions() {
        this.perm.recalculatePermissions();
    }

    @Override
    public Set<PermissionAttachmentInfo> getEffectivePermissions() {
        return this.perm.getEffectivePermissions();
    }

    @Override
    public boolean isOp() {
        return true;
    }

    @Override
    public void setOp(boolean b) {
    }

    public User getUser() {
        return user;
    }

    public org.javacord.api.entity.server.Server getDiscordServer() {
        return server;
    }
}
