package tools

import "time"

// StepMetric carries the outcome of one Argo step node as observed by oc-monitord.
// Embedded in WorkflowLifecycleEvent.Steps for the WORKFLOW_DONE_EVENT recap.
type StepMetric struct {
	BookingID string     `json:"booking_id"`
	State     int        `json:"state"`
	RealStart *time.Time `json:"real_start,omitempty"`
	RealEnd   *time.Time `json:"real_end,omitempty"`
}

// WorkflowLifecycleEvent is the NATS payload emitted by oc-monitord on
// WORKFLOW_STARTED_EVENT, WORKFLOW_STEP_DONE_EVENT, and WORKFLOW_DONE_EVENT.
//
//   - ExecutionID  : WorkflowExecution UUID (used by oc-scheduler to update state)
//   - ExecutionsID : run-group ID shared by all bookings of the same run
//   - BookingID    : non-empty only for WORKFLOW_STEP_DONE_EVENT
//   - State        : target state (enum index: SUCCESS=3, FAILURE=4, STARTED=2, …)
//   - RealStart    : actual start timestamp recorded by Argo (nil if unknown)
//   - RealEnd      : actual end timestamp recorded by Argo (nil for STARTED events)
//   - Steps        : non-nil only for WORKFLOW_DONE_EVENT — full recap of every step
//     so oc-scheduler and oc-catalog can catch up if they missed STEP_DONE events
type WorkflowLifecycleEvent struct {
	ExecutionID  string       `json:"execution_id"`
	ExecutionsID string       `json:"executions_id"`
	BookingID    string       `json:"booking_id,omitempty"`
	State        int          `json:"state"`
	RealStart    *time.Time   `json:"real_start,omitempty"`
	RealEnd      *time.Time   `json:"real_end,omitempty"`
	Steps        []StepMetric `json:"steps,omitempty"`
}
