package ports

import "context"

// SeedCounts summarizes what one seed ingest wrote, by section. Sections
// the file does not exercise stay zero.
type SeedCounts struct {
	Lifecycles        int
	EntityTypes       int
	RelationshipTypes int
	Entities          int
	Relationships     int
	Checks            int
	RiskClasses       int
	ApprovalRules     int
	AutonomySettings  int
	Documents         int
	Investigations    int
	Runbooks          int
}

// SeedRepository is the seed aggregate: bootstrap ingest (seeds/*.yaml →
// DB) and the inverse export (DB → seeds/*.yaml for DR / version
// control).
//
// Each Ingest method is one transaction — parse, validate against the
// ontology, write, and record the file's content hash in seed_versions —
// and a no-op (applied=false) when the hash is unchanged, so re-running
// `oikos seed` is idempotent. Validation failures roll back the whole
// file. Ingest order across files (ontology before inventory) is a
// SeedService concern; within inventory, default checks derive only after
// relationships exist (a service inherits its container's address).
//
// Export regenerates the three structural seed YAMLs deterministically
// (sorted maps, ordered lists) so export → ingest → export is
// byte-stable. Runtime state (cognition layer) is excluded.
type SeedRepository interface {
	IngestOntology(ctx context.Context, filename string, content []byte) (counts SeedCounts, applied bool, err error)
	IngestInventory(ctx context.Context, filename string, content []byte) (counts SeedCounts, applied bool, err error)
	IngestPolicy(ctx context.Context, filename string, content []byte) (counts SeedCounts, applied bool, err error)
	IngestKnowledge(ctx context.Context, filename string, content []byte) (counts SeedCounts, applied bool, err error)
	Export(ctx context.Context) (map[string][]byte, error)
}
