package protocol

import "time"

const (
	AccountingCheckpointRunning  = "running"
	AccountingCheckpointTerminal = "terminal"

	// These limits keep one checkpoint below TiDB's default transaction-entry
	// limit after fixed columns and the AgentTeam attempt projection are included.
	MaxAccountingUsageJSONBytes             = (64 << 10) - 1
	MaxAccountingSettlementReferences       = 4096
	MaxAccountingSettlementReferenceBytes   = 255
	MaxAccountingSettlementLineageJSONBytes = 4 << 20
)

// Principal is the exact turn authority bound into runtime persistence.
type Principal struct {
	OrganizationID string
	WorkspaceID    string
	RequesterID    string
	TurnID         string
}

// RootHandle is durable server-only authorization metadata addressed by an
// opaque random ID. RepositoryRef never crosses the runtime API boundary.
type RootHandle struct {
	ID              string
	OrganizationID  string
	WorkspaceID     string
	RequesterID     string
	TurnID          string
	KnowledgeBaseID string
	SourceID        string
	SourceName      string
	RootKind        string
	RepoRole        string
	Revision        string
	RepositoryRef   string
	DefaultRef      string
	ResolvedRef     string
	ResolvedRefKind string
	FreshnessStatus string
	ExpiresAt       time.Time
	CreatedAt       time.Time
}

// AccountingCheckpoint is a content-free aggregate of hosted-model calls for
// one exact execution attempt.
type AccountingCheckpoint struct {
	Principal      Principal
	AttemptID      string
	Generation     int
	State          string
	Usage          map[string]any
	SettlementRefs []string
	ExpiresAt      time.Time
	UpdatedAt      time.Time
}
