/*
 * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file
 * at the root of this project for more details.
 */
package io.github.nucleuspowered.nucleus.modules.invulnerability.infoprovider;

import io.github.nucleuspowered.nucleus.modules.invulnerability.InvulnerabilityPermissions;
import io.github.nucleuspowered.nucleus.modules.invulnerability.services.InvulnerabilityService;
import io.github.nucleuspowered.nucleus.core.services.INucleusServiceCollection;
import io.github.nucleuspowered.nucleus.core.services.impl.playerinformation.NucleusProvider;
import io.github.nucleuspowered.nucleus.core.services.interfaces.IMessageProviderService;
import net.kyori.adventure.text.Component;
import org.spongepowered.api.command.CommandCause;
import org.spongepowered.api.entity.living.player.User;

import java.util.Optional;

public class InvulnerabilityInfoProvider implements NucleusProvider {

    @Override public String getCategory() {
        return "invulnerability";
    }

    @Override
    public Optional<Component> get(final User user, final CommandCause source, final INucleusServiceCollection serviceCollection) {
        if (serviceCollection.permissionService().hasPermission(source, InvulnerabilityPermissions.OTHERS_GOD)) {
            final boolean godMode = serviceCollection.getServiceUnchecked(InvulnerabilityService.class).isInvulnerable(user.uniqueId());
            final IMessageProviderService messageProviderService = serviceCollection.messageProvider();
            return Optional.of(
                    messageProviderService.getMessageFor(source.audience(), "seen.godmode",
                            messageProviderService.getMessageFor(source.audience(), "standard.yesno." + Boolean.toString(godMode).toLowerCase()))
            );
        }

        return Optional.empty();
    }
}
