package unmarshal

import (
	"io"
)

// MSRCVulnerability represents a single Msrc entry with vulnerability metadata
type MSRCVulnerability struct {
	Cvss struct {
		BaseScore     float64 `json:"base_score"`
		TemporalScore float64 `json:"temporal_score"`
		Vector        string  `json:"vector"`
	} `json:"cvss"`
	FixedIn []struct {
		ID        string   `json:"id"`
		IsFirst   bool     `json:"is_first"`
		IsLatest  bool     `json:"is_latest"`
		Links     []string `json:"links"`
		Available struct {
			Date string `json:"date,omitempty"`
			Kind string `json:"kind,omitempty"`
		} `json:"available,omitempty"`
	} `json:"fixed_in"`
	ID      string `json:"id"`
	Link    string `json:"link"`
	Product struct {
		Family string `json:"family"`
		ID     string `json:"id"`
		Name   string `json:"name"`
	} `json:"product"`
	Severity   string   `json:"severity"`
	Summary    string   `json:"summary"`
	Vulnerable []string `json:"vulnerable"`
}

func (o MSRCVulnerability) IsEmpty() bool {
	return o.ID == ""
}

func MSRCVulnerabilityEntries(reader io.Reader) ([]MSRCVulnerability, error) {
	return unmarshalSingleOrMulti[MSRCVulnerability](reader)
}
