module orchestration_example

import services/common

const {
    initial_value: "Starting orchestration",
    feature_message: "Feature processing",
    solution_message: "Solution coordinating"
}

// Basic workflow that sets a value
workflow basic_step {
  start: Execute

  state Execute {
    action services/common/response.Response(value: "Basic step executed", statusCode: 200) as step_result
    on success -> End
  }

  state End {
    end ok
  }
}

// Workflow that processes data
workflow process_data {
  start: Process

  state Process {
    action services/common/response.Response(value: "Data processed", statusCode: 200) as process_result
    on success -> End
  }

  state End {
    end ok
  }
}

// Workflow that validates results
workflow validate_results {
  start: Validate

  state Validate {
    action services/common/response.Response(value: "Results validated", statusCode: 200) as validation_result
    on success -> End
  }

  state End {
    end ok
  }
}

// Feature that orchestrates multiple workflows
feature data_processing_feature {
  start: BasicStep

  state BasicStep {
    action workflow basic_step
    on success -> ProcessData
  }

  state ProcessData {
    action workflow process_data
    on success -> ValidateResults
  }

  state ValidateResults {
    action workflow validate_results
    on success -> Complete
  }

  state Complete {
    action services/common/response.Response(value: $constants.feature_message, statusCode: 200) as feature_result
    end ok
  }
}

// Another feature for reporting
feature reporting_feature {
  start: GenerateReport

  state GenerateReport {
    action services/common/response.Response(value: "Report generated", statusCode: 200) as report_result
    on success -> End
  }

  state End {
    end ok
  }
}

// Solution that orchestrates features and workflows
solution complete_solution {
  start: Initialize

  state Initialize {
    action services/common/response.Response(value: $constants.initial_value, statusCode: 200) as init_result
    on success -> RunDataProcessing
  }

  state RunDataProcessing {
    action feature data_processing_feature
    on success -> RunReporting
  }

  state RunReporting {
    action feature reporting_feature
    on success -> FinalWorkflow
  }

  state FinalWorkflow {
    action workflow basic_step
    on success -> Complete
  }

  state Complete {
    action services/common/response.Response(value: $constants.solution_message, statusCode: 200) as final_result
    end ok
  }
}
