# 570689 - Context specific Continuous Flows configuration

## Why

Currently, Continuous Flow settings (Enable/Disable, AutoReEvaluation of Ranks, and Future Merges) are configured globally, meaning the same rules apply across all flows, products, and production orders. This limits flexibility for manufacturing environments where different flows or products require distinct continuous flow behaviours. For example, Future Merges may be desirable for one flow but actively harmful for another, and there is currently no way to express that distinction without a global trade-off.

## What

We want to change the enable logic for Continuous Flows to be context specific, but also not lose the ability to enable it globally. This means that we want to be able to enable Continuous Flows for specific contexts, but if it is not enabled for a specific context, it should fall back to the global configuration.

The following logic should be implemented:

1. If global config entry is enabled, then the feature is enabled
2. If global config entry is disabled, the configuration smart table must be resolved to check if there is an entry for the current context (flow, product, etc.)

## Constraints

### Must

- Reuse code as much as possible. If necessary, create new utilities related with Continuous Flows under the `Cmf.MedDev.Common` project.

## Helpers

- The internal framework code can be found under `/workspaces/Product/MES` and `/workspaces/Product/Platform/Host`.

## Tasks

### T1: Rename existing global configuration entries for Continuous Flows to indicate that they are global settings.

- Update the names of the following config entries to reflect that they are global settings:
  - `EnableContinuousFlows` -> `EnableGlobalContinuousFlows`
  - `EnableAutoReEvaluationOfMaterialRanks` -> `EnableGlobalAutoReEvaluationOfMaterialRanks`
  - `EnableMergeFutureActionOnStepFeature` -> `EnableGlobalMergeFutureActionOnStepFeature`
  - `EnableKeepInProcessRankOnReworkMaterialReturn` -> `EnableGlobalKeepInProcessRankOnReworkMaterialReturn`

- Logic:
  - Create the new configuration entries
  - If configs with previous names exist, copy their values to the new entries and delete the old entries.

- Files
    - `Cmf.MedDev.Data/DEEs/ProcessRules/Before/CreateConfigs.cs`

### T2: Create a new configuration smart table to store context specific Continuous Flows settings.

- Define a new smart table to store context specific Continuous Flows settings. The table should have the following columns and definitions:
    - Keys
        - Flow (reference to Flow entity type)
        - LogicalFlowPath (string)
        - Product (reference to Product entity type)
        - ProductGroup (reference to ProductGroup entity type)
        - ProductionOrder (reference to ProductionOrder entity type)
    - Values
        - ContinuousFlowsEnabled (boolean)
        - AutoReEvaluationOfMaterialRanksEnabled (boolean)
        - MergeFutureActionOnStepEnabled (boolean)
        - KeepInProcessRankOnReworkMaterialReturnEnabled (boolean)
- Files
    - `Cmf.MedDev.Data/DEEs/ProcessRules/Before/CreateTables.cs`

### T3: Implement logic to determine if Continuous Flows is enabled for a specific context.

- Update the business logic to determine if any of the above settings is enabled globally or by context. The logic should follow these rules:
    1. Check if the required global configuration entry is enabled. If it is enabled, then the feature is enabled.
    2. If the global configuration entry is disabled, resolve the new configuration smart table to check if there is an entry for the current context (flow, product, etc.) with the required setting enabled. If such an entry exists, then the feature is enabled for that context.
- If more than one of the settings is required for a given method or DEE action, then best practice is to extract the resolution logic to a new utility method that can be reused across the codebase and return an object with the resolution for all settings at once, instead of resolving each setting separately.
- Files
    - Review the codebase of the `Cmf.MedDev.Common` and `Cmf.MedDev.Data` projects to identify where the Continuous Flows settings are currently being checked and update the logic accordingly.

### T4: Update unit tests
- Create new unit tests accordingly in the `Cmf.MedDev.UnitTests` project to cover the new logic for context specific Continuous Flows settings. Ensure that the tests cover both global and context specific scenarios.
- Files
    - Continuous flows related unit tests in `Cmf.MedDev.UnitTests` project.

### T5: Update technical documentation
- Update the technical documentation, covering the changes that have been performed in the configuration of Continuous Flows, including the new smart table and the logic for determining if Continuous Flows is enabled for a specific context.
- Files
    - `DocumentationPortal/docs/userguide/artifacts`

### T6: Update user guide
- Update the user guide related with continuous flows configuration to reflect the new context specific settings and how to use them.
- Files
    - `DocumentationPortal/docs/userguide/artifacts`

## Validation

After all tasks are completed, you must validate that:
- The Business and Tests solutions are compiled successfully.
- All unit tests pass successfully.