package approval_test

import (
	"testing"

	"github.com/acp/interceptor/internal/approval"
	"github.com/acp/interceptor/internal/models"
)

func TestStoreApproveDeny(t *testing.T) {
	t.Parallel()

	store := approval.NewStore(10)
	amt := int64(480000)
	req := models.ToolCallRequest{
		AgentID: "underwriter-agent",
		Tool:    "underwriting_api",
		Action:  "score_loan",
		Amount:  &amt,
		Extra:   map[string]any{"loan_amount": float64(480000)},
	}

	store.UpsertPending("trace-1", req, "loan_amount_requires_senior_uw", "acp/mortgage_underwriting")

	rec, ok := store.Get("trace-1")
	if !ok || rec.Status != approval.StatusPending {
		t.Fatalf("expected pending, got %#v", rec)
	}

	if _, err := store.Approve("trace-1", "supervisor@bank"); err != nil {
		t.Fatal(err)
	}
	rec, _ = store.Get("trace-1")
	if rec.Status != approval.StatusApproved {
		t.Fatalf("expected approved, got %s", rec.Status)
	}

	if !rec.MatchesRequest(req) {
		t.Fatal("expected request match")
	}
	req.Amount = ptrInt64(900000)
	if rec.MatchesRequest(req) {
		t.Fatal("expected mismatch after amount change")
	}
}

func ptrInt64(v int64) *int64 { return &v }
