import { IHttpStep } from './HttpStep.js'

export enum FlowSourceEnum {
  /**
   * The request object.
   */
  request = 'request',
  /**
   * The response object.
   */
  response = 'response',
  /**
   * A variable from the current environment.
   */
  variable = 'variable',
}

export enum FlowRequestDataEnum {
  url = 'url',
  method = 'method',
  headers = 'headers',
  body = 'body',
}

export enum FlowResponseDataEnum {
  url = 'url',
  status = 'status',
  statusText = 'statusText',
  headers = 'headers',
  /**
   * Reads the value of a cookie in the `set-cookie` header.
   */
  cookie = 'cookie',
  body = 'body',
}

/**
 * A flow represents a series of actions to be performed one-by-one after the HTTP request is sent or when the response
 * is ready.
 */
export interface IHttpFlow {
  /**
   * The description of the flow
   */
  description?: string
  /**
   * Describes when the flow is executed.
   * The `request` means the flow is executed before the request is sent to the HTTP engine.
   * The `response` means the flow is executed after the response has been received in full, but before reporting
   * the response to the UI.
   */
  trigger: 'request' | 'response'
  /**
   * The ordered list of actions to execute.
   */
  actions: IHttpAction[]
  /**
   * A condition to check before running the flow.
   */
  condition?: IHttpAction
}

/**
 * Describes a single action in a flow.
 * An action can have a condition that is checked against the current context.
 * Action is not executed when the condition is not meet.
 *
 * Each action has one or more steps (when 0 items then the action is ignored). Each step performs a task.
 * The result of a task is passed to the next step as an input. The result of a task may be `void`, `null`,
 * or `undefined` which is treated as `void`.
 */
export interface IHttpAction {
  /**
   * The description of the action
   */
  description?: string
  /**
   * The list of steps to perform. This is an ordered list of action tasks.
   * Each step is described by the `kind` property which tells the runner what action to perform.
   */
  steps: IHttpStep[]
}
