package filescan

import (
	"bytes"
	"context"
	"testing"

	"github.com/ultisuite/ulti-backend/internal/orgpolicy"
)

type stubPolicyLoader struct {
	fp orgpolicy.FilePolicies
}

func (s stubPolicyLoader) FilePolicies(ctx context.Context) (orgpolicy.FilePolicies, error) {
	return s.fp, nil
}

func (s stubPolicyLoader) ScanEnabled(ctx context.Context) (bool, string, error) {
	if s.fp.VirusScanEnabled && s.fp.VirusTotalAPIKey != "" {
		return true, s.fp.VirusTotalAPIKey, nil
	}
	return false, "", nil
}

func TestScannerDisabledReturnsSkipped(t *testing.T) {
	scanner := &Scanner{
		policies: stubPolicyLoader{fp: orgpolicy.FilePolicies{VirusScanEnabled: false}},
	}
	data, result, err := scanner.ScanReader(context.Background(), "test.txt", bytes.NewReader([]byte("hello")), 5)
	if err != nil {
		t.Fatalf("ScanReader: %v", err)
	}
	if result.Status != "skipped" {
		t.Fatalf("status = %q, want skipped", result.Status)
	}
	if string(data) != "hello" {
		t.Fatalf("data = %q", data)
	}
}
