// Package extension owns the flattened Agent Extension Catalog, delivery
// outbox, invocation audit, and App-hosted runtime projections. Extension
// Definitions live in the immutable Registry; App identity, installation,
// connection, authorization, and Extension selections live in the shared
// Service Actor substrate.
package extension

import (
	"fmt"

	"github.com/tidbcloud/AgentTeam/internal/coredb"
)

const (
	// PrincipalKindAgent identifies an Agent principal in an App authorization
	// row.
	PrincipalKindAgent = "agent"
)

// Store owns Extension runtime data access over the shared Service Actor
// substrate.
type Store struct {
	db coredb.DB
}

// New constructs an Extension store over the shared Service Actor substrate.
func New(db coredb.DB) *Store {
	return &Store{db: db}
}

// Validate reports whether the store is wired into a database.
func (store *Store) Validate() error {
	if store == nil || store.db == nil {
		return fmt.Errorf("extension store is not configured")
	}
	return nil
}

// InTx returns a transaction-bound Extension runtime store.
func (store *Store) InTx(tx coredb.Tx) *TxStore {
	return &TxStore{db: tx}
}

// TxStore exposes Extension runtime persistence bound to an existing
// transaction.
type TxStore struct {
	db coredb.QueryExecer
}
