package events

import (
	"bit.admedia.com/scm/ad/adpilot-indexing-code-parser.com/internal/contracts/metadata"
)

// DiagnosticSeverity indicates parser diagnostic severity.
type DiagnosticSeverity string

const (
	DiagnosticSeverityInfo    DiagnosticSeverity = "info"
	DiagnosticSeverityWarning DiagnosticSeverity = "warning"
	DiagnosticSeverityError   DiagnosticSeverity = "error"
)

// ParserDiagnostic describes a parser issue for a file or symbol.
type ParserDiagnostic struct {
	Code     string             `json:"code"`
	Message  string             `json:"message"`
	Severity DiagnosticSeverity `json:"severity"`
	FilePath string             `json:"file_path,omitempty"`
	Line     int                `json:"line,omitempty"`
}

// ParserDiagnosticsReadyEvent is published when parser diagnostics are available.
type ParserDiagnosticsReadyEvent struct {
	metadata.Envelope
	RepoID      string             `json:"repo_id"`
	SnapshotID  string             `json:"snapshot_id"`
	CommitSHA   string             `json:"commit_sha"`
	JobID       string             `json:"job_id"`
	Diagnostics []ParserDiagnostic `json:"diagnostics"`
}

// NewParserDiagnosticsReadyEvent creates a v1 parser-diagnostics-ready event.
func NewParserDiagnosticsReadyEvent(eventID, repoID, snapshotID, commitSHA, jobID string, diagnostics []ParserDiagnostic) ParserDiagnosticsReadyEvent {
	return ParserDiagnosticsReadyEvent{
		Envelope:    metadata.NewEnvelope(eventID),
		RepoID:      repoID,
		SnapshotID:  snapshotID,
		CommitSHA:   commitSHA,
		JobID:       jobID,
		Diagnostics: diagnostics,
	}
}
