package analyzer

import "git.mchus.pro/mchus/logpile/internal/models"

// Analyzer processes parsed IPMI data
type Analyzer struct {
	result *models.AnalysisResult
}

// New creates a new analyzer
func New() *Analyzer {
	return &Analyzer{}
}

// SetData sets the data to analyze
func (a *Analyzer) SetData(result *models.AnalysisResult) {
	a.result = result
}

// GetCriticalEvents returns only critical severity events
func (a *Analyzer) GetCriticalEvents() []models.Event {
	if a.result == nil {
		return nil
	}

	var critical []models.Event
	for _, e := range a.result.Events {
		if e.Severity == models.SeverityCritical {
			critical = append(critical, e)
		}
	}
	return critical
}

// GetEventsBySensorType returns events filtered by sensor type
func (a *Analyzer) GetEventsBySensorType(sensorType string) []models.Event {
	if a.result == nil {
		return nil
	}

	var filtered []models.Event
	for _, e := range a.result.Events {
		if e.SensorType == sensorType {
			filtered = append(filtered, e)
		}
	}
	return filtered
}

// GetAllSerials returns all serial numbers from FRU data
func (a *Analyzer) GetAllSerials() []models.FRUInfo {
	if a.result == nil {
		return nil
	}
	return a.result.FRU
}
