package dev.sheldan.abstracto.core.commands.config;

import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.service.ServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Component
public class SetAdminMode extends AbstractConditionableCommand {

    @Autowired
    private ServerService serverService;

    @Override
    public CommandResult execute(CommandContext commandContext) {
        Boolean newState = (Boolean) commandContext.getParameters().getParameters().get(0);
        serverService.setAdminModeTo(commandContext.getGuild().getIdLong(), newState);
        return CommandResult.fromSuccess();
    }

    @Override
    public CommandConfiguration getConfiguration() {
        Parameter valueToSet = Parameter
                .builder()
                .name("value")
                .type(Boolean.class)
                .templated(true)
                .build();
        List<Parameter> parameters = Arrays.asList(valueToSet);
        HelpInfo helpInfo = HelpInfo.builder().templated(true).hasExample(true).build();
        return CommandConfiguration.builder()
                .name("setAdminMode")
                .module(ConfigModuleDefinition.CONFIG)
                .parameters(parameters)
                .messageCommandOnly(true)
                .templated(true)
                .supportsEmbedException(true)
                .help(helpInfo)
                .causesReaction(true)
                .build();
    }

    @Override
    public FeatureDefinition getFeature() {
        return CoreFeatureDefinition.CORE_FEATURE;
    }
}
