package domain

import "time"

// Indexing run mode values.
const (
	IndexingRunModeFresh   = "fresh"
	IndexingRunModeReindex = "reindex"
)

// Indexing run status values.
const (
	IndexingRunStatusPending   = "pending"
	IndexingRunStatusRunning   = "running"
	IndexingRunStatusCompleted = "completed"
	IndexingRunStatusFailed    = "failed"
	IndexingRunStatusDegraded  = "degraded"
)

// Stage status values for indexing run stages.
const (
	StageStatusPending   = "pending"
	StageStatusRunning   = "running"
	StageStatusCompleted = "completed"
	StageStatusFailed    = "failed"
)

// IndexingRunStages tracks per-stage pipeline status for an indexing run.
type IndexingRunStages struct {
	RepoSync      string `bson:"repo_sync" json:"repo_sync"`
	DocsParse     string `bson:"docs_parse" json:"docs_parse"`
	CodeParse     string `bson:"code_parse" json:"code_parse"`
	GraphFinalize string `bson:"graph_finalize" json:"graph_finalize"`
	CommitIntel   string `bson:"commit_intel" json:"commit_intel"`
	Embedding     string `bson:"embedding,omitempty" json:"embedding,omitempty"`
}

// IndexingRun tracks pipeline progress for a single repository sync.
type IndexingRun struct {
	IndexingRunID          string            `bson:"indexing_run_id" json:"indexing_run_id"`
	JobID                  string            `bson:"job_id" json:"job_id"`
	RepoID                 string            `bson:"repo_id" json:"repo_id"`
	SnapshotID             string            `bson:"snapshot_id" json:"snapshot_id"`
	CommitSHA              string            `bson:"commit_sha" json:"commit_sha"`
	Ref                    string            `bson:"ref" json:"ref"`
	Mode                   string            `bson:"mode" json:"mode"`
	Status                 string            `bson:"status" json:"status"`
	ExpectedCodeFiles      int               `bson:"expected_code_files" json:"expected_code_files"`
	ExpectedDocsFiles      int               `bson:"expected_docs_files" json:"expected_docs_files"`
	ExpectedCommits        int               `bson:"expected_commits" json:"expected_commits"`
	ProcessedCodeFiles     int               `bson:"processed_code_files" json:"processed_code_files"`
	ProcessedDocsFiles     int               `bson:"processed_docs_files" json:"processed_docs_files"`
	FailedFiles            int               `bson:"failed_files" json:"failed_files"`
	FailedCommits          int               `bson:"failed_commits,omitempty" json:"failed_commits,omitempty"`
	FailedEmbeddings       int               `bson:"failed_embeddings,omitempty" json:"failed_embeddings,omitempty"`
	CodeParseFailureRate   float64           `bson:"code_parse_failure_rate,omitempty" json:"code_parse_failure_rate,omitempty"`
	CommitIntelFailureRate float64           `bson:"commit_intel_failure_rate,omitempty" json:"commit_intel_failure_rate,omitempty"`
	EmbeddingFailureRate   float64           `bson:"embedding_failure_rate,omitempty" json:"embedding_failure_rate,omitempty"`
	Stages                 IndexingRunStages `bson:"stages" json:"stages"`
	Error                  string            `bson:"error,omitempty" json:"error,omitempty"`
	StartedAt              time.Time         `bson:"started_at" json:"started_at"`
	CompletedAt            *time.Time        `bson:"completed_at,omitempty" json:"completed_at,omitempty"`
}
