using System.Linq;
using Dalamud.Plugin;
using HellionChat.Resources;

namespace HellionChat;

internal static class ChatTwoConflictDetector
{
    private const string UpstreamInternalName = "ChatTwo";

    public static void ThrowIfChatTwoIsLoaded(IDalamudPluginInterface pluginInterface)
    {
        var conflict = pluginInterface.InstalledPlugins.FirstOrDefault(p =>
            p.InternalName == UpstreamInternalName && p.IsLoaded
        );

        if (conflict is null)
            return;

        var message =
            HellionStrings.ChatTwoConflictTitle
            + "\n\n"
            + HellionStrings.ChatTwoConflictBody
            + "\n\n"
            + HellionStrings.ChatTwoConflictAction;

        throw new System.InvalidOperationException(message);
    }
}
