package exec

import "time"

// workflowRunStartResponse is the business receipt returned when a Plan starts.
// Invocation remains an internal audit record and is intentionally not exposed.
type workflowRunStartResponse struct {
	RunID         string    `json:"runId"`
	Status        string    `json:"status"`
	PlanID        string    `json:"planId"`
	PlanVersionID string    `json:"planVersionId"`
	AcceptedAt    time.Time `json:"acceptedAt"`
	Replayed      bool      `json:"replayed,omitempty"`
}

type workflowRunResponse struct {
	ID              string                      `json:"id"`
	PlanID          string                      `json:"planId"`
	PlanKey         string                      `json:"planKey,omitempty"`
	PlanDisplayName string                      `json:"planDisplayName,omitempty"`
	PlanVersionID   string                      `json:"planVersionId"`
	Status          string                      `json:"status"`
	Input           workflowValue               `json:"input,omitempty"`
	Output          workflowValue               `json:"output,omitempty"`
	ErrorCode       string                      `json:"errorCode,omitempty"`
	Error           workflowOperationalJSON     `json:"error,omitempty"`
	InputRef        *workflowPayloadRefResponse `json:"inputRef,omitempty"`
	OutputRef       *workflowPayloadRefResponse `json:"outputRef,omitempty"`
	QueuedAt        time.Time                   `json:"queuedAt"`
	StartedAt       *time.Time                  `json:"startedAt,omitempty"`
	CompletedAt     *time.Time                  `json:"completedAt,omitempty"`
	CanceledAt      *time.Time                  `json:"canceledAt,omitempty"`
}

type workflowRunStepView struct {
	StepID     string                  `json:"stepId"`
	Type       string                  `json:"type"`
	Status     string                  `json:"status"`
	Attempt    int64                   `json:"attempt"`
	DeadlineAt *time.Time              `json:"deadlineAt,omitempty"`
	ErrorCode  string                  `json:"errorCode,omitempty"`
	Error      workflowOperationalJSON `json:"error,omitempty"`
}

type workflowRunWaitingResponse struct {
	Kind string `json:"kind"`
	// Reason is a stable machine-readable waiting explanation. The
	// responder_capacity value never carries candidate identity.
	Reason     string     `json:"reason,omitempty"`
	StepID     string     `json:"stepId,omitempty"`
	DeadlineAt *time.Time `json:"deadlineAt,omitempty"`
}

type workflowRunShowResponse struct {
	Run         workflowRunResponse          `json:"run"`
	CurrentStep *workflowRunStepView         `json:"currentStep,omitempty"`
	WaitingOn   *workflowRunWaitingResponse  `json:"waitingOn,omitempty"`
	Payload     *workflowPayloadPageResponse `json:"payload,omitempty"`
}

type workflowRunLogEntryResponse struct {
	Sequence   int64                       `json:"sequence"`
	Time       time.Time                   `json:"time"`
	Level      string                      `json:"level"`
	Kind       string                      `json:"kind"`
	StepID     string                      `json:"stepId,omitempty"`
	Message    string                      `json:"message"`
	Details    workflowOperationalJSON     `json:"details,omitempty"`
	DetailsRef *workflowPayloadRefResponse `json:"detailsRef,omitempty"`
}

type workflowRunLogDetailEntryResponse struct {
	Sequence   int64     `json:"sequence"`
	Time       time.Time `json:"time"`
	Kind       string    `json:"kind"`
	Details    string    `json:"details"`
	Encoding   string    `json:"encoding"`
	Cursor     string    `json:"cursor,omitempty"`
	NextCursor string    `json:"nextCursor,omitempty"`
	Bytes      int       `json:"bytes"`
	TotalBytes int       `json:"totalBytes"`
	Complete   bool      `json:"complete"`
}

type workflowRunLogsDetailsResponse struct {
	Items      []workflowRunLogDetailEntryResponse `json:"items"`
	NextCursor string                              `json:"nextCursor,omitempty"`
	RunStatus  string                              `json:"runStatus"`
	Terminal   bool                                `json:"terminal"`
}

type workflowRunLogsResponse struct {
	Items      []workflowRunLogEntryResponse `json:"items"`
	NextCursor string                        `json:"nextCursor,omitempty"`
	RunStatus  string                        `json:"runStatus"`
	Terminal   bool                          `json:"terminal"`
}

type workflowRunListResponse struct {
	Items      []workflowRunResponse `json:"items"`
	NextCursor string                `json:"nextCursor,omitempty"`
}

type workflowRunCancelResponse struct {
	Run      workflowRunResponse `json:"run"`
	Replayed bool                `json:"replayed"`
}
