package system

import (
	"github.com/shirou/gopsutil/disk"
	"os"
	"path/filepath"
	"time"
)

func (i *InfoUtils) GetDiskPartitions() []disk.PartitionStat {
	partitions, _ := disk.Partitions(true)
	return partitions
}

func (i *InfoUtils) GetDiskUsage(diskPath string) *disk.UsageStat {
	usageStat, _ := disk.Usage(diskPath)
	return usageStat
}

func (i *InfoUtils) GetIOCounters() map[string]disk.IOCountersStat {
	info, _ := disk.IOCounters()
	return info
}

type FileEntry struct {
	Path      string
	Name      string
	IsDir     bool
	IsSymlink bool
	ModTime   time.Time
	Size      int64
}

func (i *InfoUtils) ScanDir(path string) ([]*FileEntry, error) {
	entries, err := os.ReadDir(path)
	data := make([]*FileEntry, 0, len(entries))
	for _, entry := range entries {
		info, _ := entry.Info()
		_path := filepath.Join(path, entry.Name())

		info.Size()
		info.ModTime()

		data = append(data, &FileEntry{
			Path:      _path,
			Name:      entry.Name(),
			IsDir:     entry.IsDir(),
			IsSymlink: entry.Type() == os.ModeSymlink,
			Size:      info.Size(),
			ModTime:   info.ModTime(),
		})
	}
	return data, err
}
