package core

// DagContinueOn controls whether a step continues on failure/skip.
type DagContinueOn struct {
	Failure bool
	Skipped bool
	// ExitCodes lists exit codes that are tolerated: if the step exits with one
	// of these non-zero codes, it is treated as a non-failure (the DAG keeps
	// going and the run is not marked failed). The real exit code is still
	// recorded. Empty means only exit 0 is a success (unless Failure is set).
	ExitCodes []int
}

// DagRetryPolicy configures automatic retries for a step.
type DagRetryPolicy struct {
	Limit       int
	IntervalSec int
}

// DagStep represents a single step in a DAG workflow.
type DagStep struct {
	Name        string
	ID          string
	Description string
	Command     string
	Script      string
	Args        []string
	Function    string `json:"function,omitempty"` // ID de funcion del registry (ej "audit_capability_groups_go_infra"). Si set, Command/Script se ignoran; el executor construye "fn run <Function> <Args...>".
	Shell       string
	Dir         string
	Depends     []string
	Env         map[string]string
	ContinueOn  DagContinueOn
	RetryPolicy DagRetryPolicy
	TimeoutSec  int
	Output      string
	Tags        []string
}

// DagHandlers contains lifecycle handler steps.
type DagHandlers struct {
	Init    []DagStep
	Success []DagStep
	Failure []DagStep
	Exit    []DagStep
}

// DagDefinition is a complete DAG workflow parsed from YAML.
type DagDefinition struct {
	Name        string
	Description string
	Group       string
	Type        string // "graph" or "" (chain/sequential)
	WorkingDir  string
	Shell       string
	Env         map[string]string
	Schedule    []string
	Steps       []DagStep
	HandlerOn   DagHandlers
	Tags        []string
	TimeoutSec  int
	FilePath    string
}

// DagValidationResult contains validation output.
type DagValidationResult struct {
	Valid    bool
	Errors   []string
	Warnings []string
	Levels   [][]string // topological levels (step names/IDs)
}
