using ClawdDotNet.Core.Staging;
using Shouldly;

namespace ClawdDotNet.Core.Tests.Staging;

public sealed class StagingPolicyTests
{
    [Theory]
    [InlineData("Mail", "send")]
    [InlineData("Telegram", "send_message")]
    [InlineData("Database", "insert")]
    [InlineData("Database", "upsert")]
    [InlineData("FileRW", "delete")]
    [InlineData("FTP", "upload")]
    [InlineData("FTP", "delete")]
    public void Irreversible_Aktionen_brauchen_standardmaessig_eine_Freigabe(string tool, string action)
        => new StagingPolicy().Decide(tool, action).ShouldBe(StagingDecision.Approve);

    [Theory]
    [InlineData("Mail", "read_inbox")]
    [InlineData("FileRW", "read")]
    [InlineData("Database", "query")]
    [InlineData("FTP", "download")]
    public void Lesende_Aktionen_laufen_ohne_Freigabe(string tool, string action)
        => new StagingPolicy().Decide(tool, action).ShouldBe(StagingDecision.Auto);

    [Fact]
    public void Die_speziellere_Regel_gewinnt()
    {
        var policy = new StagingPolicy(new Dictionary<string, StagingDecision>
        {
            ["FileRW"] = StagingDecision.Approve,        // ganzes Tool
            ["FileRW.read"] = StagingDecision.Auto       // aber Lesen frei
        });

        policy.Decide("FileRW", "read").ShouldBe(StagingDecision.Auto);
        policy.Decide("FileRW", "write").ShouldBe(StagingDecision.Approve);
    }

    [Fact]
    public void Ohne_passende_Regel_gilt_der_Standard()
    {
        new StagingPolicy(new Dictionary<string, StagingDecision>())
            .Decide("Irgendein", "ding").ShouldBe(StagingDecision.Auto);

        new StagingPolicy(new Dictionary<string, StagingDecision>(), StagingDecision.Deny)
            .Decide("Irgendein", "ding").ShouldBe(StagingDecision.Deny);
    }
}
