package events

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

// SymbolType describes the kind of parsed symbol.
type SymbolType string

const (
	SymbolTypeFunction SymbolType = "function"
	SymbolTypeMethod   SymbolType = "method"
	SymbolTypeType     SymbolType = "type"
	SymbolTypeVariable SymbolType = "variable"
	SymbolTypePackage  SymbolType = "package"
)

// CodeChunk is a parseable unit emitted by the parser service.
type CodeChunk struct {
	ChunkID    string     `json:"chunk_id"`
	SymbolName string     `json:"symbol_name"`
	SymbolType SymbolType `json:"symbol_type"`
	Text       string     `json:"text,omitempty"`
	StartLine  int        `json:"start_line"`
	EndLine    int        `json:"end_line"`
}

// ChunksReadyEvent is published when parsed chunks are ready for downstream use.
type ChunksReadyEvent struct {
	metadata.Envelope
	RepoID      string      `json:"repo_id"`
	SnapshotID  string      `json:"snapshot_id"`
	CommitSHA   string      `json:"commit_sha"`
	FilePath    string      `json:"file_path"`
	Language    string      `json:"language"`
	Chunks      []CodeChunk `json:"chunks"`
	ArtifactURI string      `json:"artifact_uri,omitempty"`
}

// NewChunksReadyEvent creates a v1 chunks-ready event.
func NewChunksReadyEvent(eventID, repoID, snapshotID, commitSHA, filePath, language string, chunks []CodeChunk) ChunksReadyEvent {
	return ChunksReadyEvent{
		Envelope:   metadata.NewEnvelope(eventID),
		RepoID:     repoID,
		SnapshotID: snapshotID,
		CommitSHA:  commitSHA,
		FilePath:   filePath,
		Language:   language,
		Chunks:     chunks,
	}
}
