package logic

import (
	"os"
	"strings"
	"testing"
	"time"
)

const (
	Output = `----------- SCAN SUMMARY -----------
Infected files: 0
Time: 0.981 sec (0 m 0 s)
Start Date: 2026:02:14 09:39:02
End Date:   2026:02:14 09:39:03`
)

func TestRegext(t *testing.T) {
	lines := strings.Split(Output, "\n")
	for _, i := range lines {
		if ReInfectedFile.MatchString(i) {
			f := ReInfectedFile.FindStringSubmatch(i)
			for _, ff := range f {
				t.Log(ff)
			}
		}
	}
}

func TestScanFile(t *testing.T) {
	target := "./hycusmutool"
	start := time.Now()
	have, err := ScanFile(target)
	dua := time.Since(start)

	if have {
		t.Logf("%s is bd", target)
	}

	t.Logf("used time: %dms", dua.Milliseconds())
	if err != nil {
		t.Error(err)
	}
}

func TestParseInt(t *testing.T) {
	i, err := ParseInt("-321")
	if err != nil {
		t.Error(err)
	}
	t.Logf("%d", i)
}

func TestPids(t *testing.T) {
	content, err := os.ReadFile("../../../asset/sftp.log")
	if err != nil {
		t.Error(err)
	}
	lines := strings.Split(string(content), "\n")
	start := time.Now()
	for _, v := range lines {
		if len(v) > 0 {
			_, err := ParseSftpLog(v)
			if err != nil {
				t.Error(err)
			}
		}
	}
	tt := time.Since(start)
	t.Logf("%d ms", tt.Milliseconds())
}

func TestParseSftpLog(t *testing.T) {
	sla, err := ParseSftpLog(`Mar 17 16:38:23 anolis sftp-server[62785]: close "/tmp/Everything-1.4.1.1030.x64-Setup. exe.tabby-upload" bytes read 0 written 1987848`)
	if err != nil {
		t.Error(err)
	}
	op := sla.(*SftpLogClose)
	t.Logf("%+v", op)
}
