using NQBot.Sdk;

namespace NQBot.Plugin.Hello;

/// <summary>最小示例插件:收到“你好”时 @ 发送者并回复。</summary>
public sealed class HelloPlugin : BotPluginBase, IConfigurablePlugin
{
    private HelloConfig _config = new();

    public override string Id => "hello";
    public override string Name => "Hello 示例";
    public override string Version => "1.0.0";
    public override string Author => "Muo";
    public override string Description => "收到“你好”或“hello”时回复一句话。";

    /// <summary>加载配置并保存上下文。</summary>
    public override void OnLoad(IPluginContext context)
    {
        base.OnLoad(context);
        _config = PluginHelpers.LoadConfig(context, () => new HelloConfig());
    }

    /// <summary>只处理群消息,匹配关键词后回复。</summary>
    public override void OnEvent(BotEvent evt)
    {
        if (evt.Kind != BotEventKind.GroupMessage) return;
        if (!_config.Enabled) return;
        string text = PluginHelpers.CleanText(evt.Text);
        if (!PluginHelpers.MatchesAny(text, new[] { "你好", "hello" })) return;
        _ = Context.Actions.SendGroupTextAtAsync(evt.GroupId, evt.UserId, _config.Reply);
    }

    /// <summary>声明由宿主自动生成设置页的配置项。</summary>
    public IReadOnlyList<PluginOption> GetOptions() => new[]
    {
        new PluginOption("enabled", "启用插件", PluginOptionType.Bool, "true"),
        new PluginOption("reply", "回复内容", PluginOptionType.Text, "你好呀!")
    };
}

/// <summary>示例插件配置,保存在插件数据目录的 config.json。</summary>
public sealed class HelloConfig
{
    public bool Enabled { get; set; } = true;
    public string Reply { get; set; } = "你好呀!";
}