package controlplane

import "encoding/json"

// ComponentWriteSurface names a logical table/fact a component kind writes to.
type ComponentWriteSurface struct {
	Table string
	Fact  string
}

// ComponentKindContract is the public, neutral subset of the engine's component
// kind contract. Engine-only build/identity fields are intentionally excluded.
type ComponentKindContract struct {
	Kind               ComponentKind
	Phase              InstallPlanPhase
	WriteSet           []ComponentWriteSurface
	BusinessKey        string
	OwnerDiscriminator ComponentOwnerStrategy
	Manageabilities    map[Manageability]struct{}
	VerifyProjection   string
	CollisionKey       string
}

// SourceBackedComponentCapability advertises a source-backed component kind's
// installability and supported manageabilities.
type SourceBackedComponentCapability struct {
	Kind            ComponentKind
	Installable     bool
	Manageabilities map[Manageability]struct{}
}

// ComponentBuildHandler builds a single component from a build request against a
// build context.
type ComponentBuildHandler func(ComponentBuildContext, ComponentBuildRequest) error

// ComponentKindRegistration binds a component kind's contract, capability,
// allowed categories, and build handler together.
type ComponentKindRegistration struct {
	Contract          ComponentKindContract
	Capability        SourceBackedComponentCapability
	AllowedCategories []PackCategory
	BuildHandler      ComponentBuildHandler
	ManagedProvider   *ComponentManagedProvider
}

// ComponentReference declares an ordering/availability dependency on another
// component in the same source-backed manifest.
type ComponentReference struct {
	Kind        ComponentKind `json:"kind"`
	BusinessKey string        `json:"businessKey"`
	Required    bool          `json:"required"`
}

// ManifestComponent is the public subset of a manifest component entry. JSON
// tags mirror the engine manifest wire shape for the fields kept here.
type ManifestComponent struct {
	Kind          ComponentKind        `json:"kind"`
	BusinessKey   string               `json:"businessKey"`
	Manageability Manageability        `json:"manageability"`
	Path          string               `json:"path,omitempty"`
	Payload       json.RawMessage      `json:"payload,omitempty"`
	DependsOn     []ComponentReference `json:"dependsOn,omitempty"`
}

// ComponentBuildRequest carries the inputs to a component build handler.
type ComponentBuildRequest struct {
	PackName  string
	Component ManifestComponent
	Payload   []byte
}

// ComponentObjectSchema is the neutral projection of an object's schema looked
// up during a component build. It is a minimal stub; fields are added when a
// real consumer needs them.
type ComponentObjectSchema struct{}
