package models

// FlowExecutionResult is the cross-repo result shape for flow execution.
type FlowExecutionResult struct {
	ActionName    string                 `json:"actionName"`
	IsSuccess     bool                   `json:"isSuccess"`
	Errors        []FlowExecutionError   `json:"errors,omitempty"`
	OutputValues  map[string]interface{} `json:"outputValues,omitempty"`
	IsCustomError bool                   `json:"-"`
	IsRetriable   bool                   `json:"-"`
}

// FlowExecutionOutcome is the direct-Go-only envelope used by connector-aware
// executors. Keeping the dependency outside FlowExecutionResult preserves the
// public result's source-compatible struct shape. All fields are deliberately
// excluded from generic JSON persistence: the envelope carries exact IDs and
// must cross only reviewed typed L0 boundaries.
type FlowExecutionOutcome struct {
	Result     *FlowExecutionResult            `json:"-"`
	Dependency *FlowExecutionDependencyRequest `json:"-"`
}

// FlowExecutionTypedOutcome is the opt-in direct-Go envelope for execution
// identity and stable failure taxonomy. It is separate from
// FlowExecutionOutcome so existing unkeyed literals remain source compatible.
type FlowExecutionTypedOutcome struct {
	Result      *FlowExecutionResult            `json:"-"`
	Dependency  *FlowExecutionDependencyRequest `json:"-"`
	ExecutionID string                          `json:"-"`
	Cause       *FlowExecutionCause             `json:"-"`
}

// FlowExecutionCause is the stable, message-free classification of the
// underlying Flow failure. Result.Errors remains the caller-facing/presented
// error surface; Cause identifies what actually failed before a fault route or
// CustomError presentation changed that surface.
type FlowExecutionCause struct {
	Code        string
	Category    FlowExecutionCauseCategory
	ElementType string
	ElementName string
	Retriable   bool
}

// FlowExecutionCauseCategory is intentionally product- and database-neutral.
// Concrete runtimes map their native errors to these stable categories.
type FlowExecutionCauseCategory string

const (
	FlowExecutionCauseCategoryValidation    FlowExecutionCauseCategory = "validation"
	FlowExecutionCauseCategoryConcurrency   FlowExecutionCauseCategory = "concurrency"
	FlowExecutionCauseCategoryPersistence   FlowExecutionCauseCategory = "persistence"
	FlowExecutionCauseCategoryConfiguration FlowExecutionCauseCategory = "configuration"
	FlowExecutionCauseCategoryAuthorization FlowExecutionCauseCategory = "authorization"
	FlowExecutionCauseCategoryNotFound      FlowExecutionCauseCategory = "not_found"
	FlowExecutionCauseCategoryExternal      FlowExecutionCauseCategory = "external"
	FlowExecutionCauseCategoryInternal      FlowExecutionCauseCategory = "internal"
	FlowExecutionCauseCategoryUnknown       FlowExecutionCauseCategory = "unknown"
)

// FlowExecutionError is the cross-repo error shape for flow execution.
type FlowExecutionError struct {
	StatusCode string   `json:"statusCode"`
	Message    string   `json:"message"`
	Fields     []string `json:"fields,omitempty"`
}
