// Package chunkmap owns the durable accepted source chunk-map contract.
package chunkmap

import (
	"gitea.maximumdirect.net/eric/notarius/internal/core/source"
	"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
)

const (
	ArtifactKind  contracts.ArtifactKind = "source/chunk-map"
	SchemaID                             = "notarius.source.chunk_map"
	SchemaName                           = "notarius_source_chunk_map_v1"
	SchemaVersion                        = "v1"
	MediaType                            = "application/json"
)

// ChunkMap is the durable representation of one accepted materialized chunk plan.
type ChunkMap struct {
	SourceID         string                  `json:"source_id"`
	SourceDigest     string                  `json:"source_digest"`
	PlanDigest       string                  `json:"plan_digest"`
	RequestedChunker string                  `json:"requested_chunker"`
	Producer         Producer                `json:"producer"`
	PlanAnnotations  source.ChunkAnnotations `json:"plan_annotations"`
	Chunks           []Chunk                 `json:"chunks"`
}

// Producer identifies the component that produced the accepted logical plan.
type Producer struct {
	InputModule string `json:"input_module"`
	ChunkModule string `json:"chunk_module"`
	LLMProfile  string `json:"llm_profile,omitempty"`
}

// Chunk describes one accepted materialized range without source content.
type Chunk struct {
	ID          string                  `json:"id"`
	Index       int                     `json:"index"`
	SourceRef   source.SourceRef        `json:"source_ref"`
	UnitCount   int                     `json:"unit_count"`
	Annotations source.ChunkAnnotations `json:"annotations"`
}

// BuildRequest supplies the accepted runtime state used to build a chunk map.
type BuildRequest struct {
	Source           *source.SourceDocument
	Plan             source.ChunkPlan
	Chunks           []source.Chunk
	RequestedChunker string
	Producer         Producer
}
