package orchestrator

import (
	"github.com/Fimeg/RedFlag/aggregator-agent/internal/client"
)

// StorageMetric represents a single storage/disk metric
type StorageMetric struct {
	Mountpoint        string                 `json:"mountpoint"`
	Filesystem        string                 `json:"filesystem"`
	Device            string                 `json:"device"`
	DiskType          string                 `json:"disk_type"`
	TotalBytes        int64                  `json:"total_bytes"`
	UsedBytes         int64                  `json:"used_bytes"`
	AvailableBytes    int64                  `json:"available_bytes"`
	UsedPercent       float64                `json:"used_percent"`
	IsRoot            bool                   `json:"is_root"`
	IsLargest         bool                   `json:"is_largest"`
	Severity          string                 `json:"severity"`
	Metadata          map[string]interface{} `json:"metadata"`
}

// SystemMetric represents a single system metric (CPU, memory, etc.)
type SystemMetric struct {
	MetricName        string                 `json:"metric_name"`
	MetricType        string                 `json:"metric_type"` // "cpu", "memory", "processes", "uptime", etc.
	CurrentValue      string                 `json:"current_value"`
	AvailableValue    string                 `json:"available_value"`
	Severity          string                 `json:"severity"`
	Metadata          map[string]interface{} `json:"metadata"`
}

// DockerImage represents a single Docker image
type DockerImage struct {
	ImageName         string                 `json:"image_name"`
	ImageTag          string                 `json:"image_tag"`
	ImageID           string                 `json:"image_id"`
	RepositorySource   string                 `json:"repository_source"`
	SizeBytes         int64                  `json:"size_bytes"`
	CreatedAt         string                 `json:"created_at"`
	HasUpdate         bool                   `json:"has_update"`
	LatestImageID     string                 `json:"latest_image_id"`
	Severity          string                 `json:"severity"`
	Labels            map[string]string      `json:"labels"`
	Metadata          map[string]interface{} `json:"metadata"`
}

// PackageUpdate represents an actual software package update (legacy, for package scanners only)
type PackageUpdate = client.UpdateReportItem

// --- Scanner Interfaces ---

// StorageScannerInterface handles storage/disk metrics scanning
type StorageScannerInterface interface {
	IsAvailable() bool
	ScanStorage() ([]StorageMetric, error)
	Name() string
}

// SystemScannerInterface handles system metrics scanning
type SystemScannerInterface interface {
	IsAvailable() bool
	ScanSystem() ([]SystemMetric, error)
	Name() string
}

// DockerScannerInterface handles Docker image scanning
type DockerScannerInterface interface {
	IsAvailable() bool
	ScanDocker() ([]DockerImage, error)
	Name() string
}

// PackageScannerInterface handles package update scanning (legacy)
type PackageScannerInterface interface {
	IsAvailable() bool
	ScanPackages() ([]PackageUpdate, error)
	Name() string
}

// --- Unified Scanner Types for Backwards Compatibility ---

// ScannerType represents the type of data a scanner returns
type ScannerType string

const (
	ScannerTypeStorage ScannerType = "storage"
	ScannerTypeSystem  ScannerType = "system"
	ScannerTypeDocker  ScannerType = "docker"
	ScannerTypePackage ScannerType = "package"
)

// TypedScannerResult represents the result of any type of scanner
type TypedScannerResult struct {
	ScannerName string
	ScannerType ScannerType
	StorageData []StorageMetric
	SystemData  []SystemMetric
	DockerData  []DockerImage
	PackageData []PackageUpdate
	Error       error
	Duration    int64 // milliseconds
	Status      string
}

// TypedScanner is a unified interface that can return any type of data
type TypedScanner interface {
	IsAvailable() bool
	GetType() ScannerType
	Scan() (TypedScannerResult, error)
	Name() string
}