# Add Future Support to Existing KOS Model

This generator adds Future support to an existing KOS model, transforming it to support progress tracking for long-running operations.

## Usage

### Via CLI
```bash
# Interactive mode - automatically discovers and lists all available models
kos-cli add-future

# With parameters
kos-cli add-future --modelName=MyModel --futureType=minimal --project=my-project

# Direct Nx
nx generate @kosdev-code/kos-nx-plugin:kos-add-future-to-model --modelName=MyModel --modelProject=my-project --futureType=complete
```

### Parameters

- `modelName` (required): Name of the existing model to add Future support to
- `modelProject` (required): Project where the model is located  
- `futureType`: Type of Future support (`minimal` or `complete`, defaults to `minimal`)
- `updateServices`: Whether to update/create services file (defaults to `true`)
- `dryRun`: Show what would be changed without making actual modifications

## What It Does

### Model File Changes
- Adds Future-related imports
- Adds Future properties (`futureHandler`, `future` for complete mode)
- Adds mixin setup call in constructor
- Adds `@kosFuture()` placeholder method
- Updates public type with `ExternalFutureInterface` intersection
- Adds `onFutureUpdate` method (for complete mode)
- Updates class implements clause (for complete mode)

### Services File Changes
- Adds `FutureResponse` import
- Creates placeholder Future operation service method
- Adds progress and result type definitions
- Creates file if it doesn't exist

### Registration File Changes  
- Adds `as any` type cast for intersection type
- Updates documentation with Future capabilities
- Adds Future usage examples

## Example Transformation

**Before:**
```typescript
export type MyModel = PublicModelInterface<MyModelImpl>;

@kosModel(MODEL_TYPE)
export class MyModelImpl implements IKosDataModel, IKosIdentifiable {
  constructor(modelId: string, options: MyOptions, context: KosCreationContext) {
    this.id = modelId;
    this.logger = context.logger;
  }
}
```

**After (minimal):**
```typescript
import { kosFuture, setupMinimalFutureSupport } from "@kosdev-code/kos-ui-sdk";
import type { ExternalFutureInterface, FutureAwareContainer } from "@kosdev-code/kos-ui-sdk";
import type { MyOperationProgress } from "./services";

export type MyModel = PublicModelInterface<MyModelImpl> & ExternalFutureInterface<MyOperationProgress>;

@kosModel(MODEL_TYPE)
export class MyModelImpl implements IKosDataModel, IKosIdentifiable {
  // Future support properties - guaranteed by framework
  public futureHandler!: FutureAwareContainer<MyOperationProgress>;
  
  constructor(modelId: string, options: MyOptions, context: KosCreationContext) {
    this.id = modelId;
    this.logger = context.logger;
    
    // Initialize Future support
    setupMinimalFutureSupport(this);
  }
  
  @kosFuture()
  async performLongRunningOperation(): Promise<void> {
    // TODO: Implement your long-running operation here
    this.logger.debug(`Starting long-running operation for ${this.id}`);
    await new Promise(resolve => setTimeout(resolve, 1000));
    this.logger.debug(`Completed long-running operation for ${this.id}`);
  }
}
```

## Next Steps After Generation

1. **Implement the @kosFuture method**: Replace the placeholder with your actual long-running operation
2. **Update service method**: Implement the generated service method to return a proper `FutureResponse`
3. **Define progress types**: Customize the `OperationProgress` and `OperationResult` types for your specific use case
4. **Customize onFutureUpdate** (complete mode): Add custom logic for handling Future state changes

## Error Handling

- Validates that the model file exists before transformation
- Provides clear error messages for missing files or invalid configurations
- Supports dry-run mode to preview changes before applying them