/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
<% if (futureAware && futureAware !== 'none') { %>/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
<% } %><% const hasFutureSupport = futureAware && futureAware !== 'none'; %>
<% const isCompleteFuture = futureAware === 'complete'; %>
<% const isCompositionCompanion = companion && companionPattern === 'composition'; %>
<% const isDecoratorCompanion = companion && companionPattern === 'decorator'; %>
<% if (internal) { %>import { kosModel<% if (parentAware) { %>, kosParentAware<% } %><% if (hasFutureSupport) { %>, kosFuture, kosFutureAware, Kos<% if (isCompleteFuture) { %>FutureAwareFull<% } else { %>FutureAwareMinimal<% } %><% } %>, kosLoggerAware, KosLoggerAware } from "../../../core/core/decorators";
import type {
  IKosDataModel,
  KosContextLogger
} from "../../../core/core/kosModel";
import type { KosModelRegistrationType } from "../../../core/core/registration/model-registration";
import type { IKosIdentifiable } from "../../../core/core/types";
import type { PublicModelInterface } from "../../../core/types";
<% if (hasFutureSupport) { %>import type { 
  ExternalFutureInterface,
  IFutureModel
} from "../../../models/types/future-interfaces";<% } %>
<% if (isDecoratorCompanion) { %>import { KosCompanionDecorator } from "../../../core/core/decorators";<% } %>
<% } else { %>import type { IKosDataModel, IKosIdentifiable, PublicModelInterface, KosModelRegistrationType<% if (hasFutureSupport) { %>, ExternalFutureInterface, IFutureModel<% } %><% if (isDecoratorCompanion) { %>, KosCompanionDecorator<% } %>  } from "@kosdev-code/kos-ui-sdk";
import { kosModel<% if (parentAware) { %>, kosParentAware<% } %><% if (hasFutureSupport) { %>, kosFuture, kosFutureAware, Kos<% if (isCompleteFuture) { %>FutureAwareFull<% } else { %>FutureAwareMinimal<% } %><% } %><% if (isDecoratorCompanion) { %>, kosCompanion<% } %>, kosLoggerAware, KosLoggerAware } from "@kosdev-code/kos-ui-sdk";
<% } %>
import type { <%= nameProperCase %>Options} from "./types";
<% if (hasFutureSupport) { %>import type { <%= nameProperCase %>OperationProgress } from "./services";<% } %>

<% if (companion) {%>
import type { <%= companionModelProperCase %>Model } from "<%= companionModelProject %>";
<% } %>
export const MODEL_TYPE = "<%= nameDashCase %>-model";

export type <%= nameProperCase %>Model = PublicModelInterface<<%= nameProperCase %>ModelImpl><% if (hasFutureSupport) { %> & ExternalFutureInterface<<%= nameProperCase %>OperationProgress><% } %>;

// Interface merging for decorator type safety
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface <%= nameProperCase %>ModelImpl extends KosLoggerAware<% if (hasFutureSupport) { %>, Kos<% if (isCompleteFuture) { %>FutureAwareFull<% } else { %>FutureAwareMinimal<% } %><<%= nameProperCase %>OperationProgress><% } %><% if (isDecoratorCompanion) { %>, KosCompanionDecorator<<%= companionModelProperCase %>Model><% } %> {}

@kosModel({ modelTypeId: MODEL_TYPE<% if (singleton !== undefined) { %>, singleton: <%= singleton %><% } %><% if (autoRegister) { %>, autoRegister: true<% } %> })
<% if (parentAware && !isDecoratorCompanion) { %>@kosParentAware()<% } %>
<% if (hasFutureSupport) { %>@kosFutureAware(<% if (!isCompleteFuture) { %>{ mode: 'minimal' }<% } %>)<% } %>
<% if (isDecoratorCompanion) { %>@kosCompanion()<% } %>
@kosLoggerAware()
export class <%= nameProperCase %>ModelImpl implements  IKosDataModel, IKosIdentifiable  {
    // Registration property for type safety - actual value injected by @kosModel decorator
    static Registration: KosModelRegistrationType<<%= nameProperCase %>Model, <%= nameProperCase %>Options>;

    id: string;
    // logger property is automatically provided by @kosLoggerAware decorator
    <% if (isCompositionCompanion) { %>
    // Composition pattern - explicit parent access
    public readonly parent: <%= companionModelProperCase %>Model;
    <% } %>
    <% if (hasFutureSupport) { %>
    // Future support properties are provided via interface merging - no need to declare<% } %>
    
    constructor(modelId: string, options: <%= nameProperCase %>Options) {
        this.id = modelId;
        // logger is automatically injected by @kosLoggerAware decorator
        <% if (isCompositionCompanion) { %>
        // Set parent from companionParent option for composition pattern
        this.parent = options.companionParent;
        <% } %>
        <% if (isDecoratorCompanion) { %>
        // Companion decorator automatically provides getCompanionParent() and parent property proxying
        <% } %>
        if (options) {
        // Copy options VERBATIM (this.x = options.x). Derivation belongs in
        // computed getters or the DTO mapper — never transform inputs here.
        }
    }

    updateModel(_options: <%= nameProperCase %>Options): void {
        // Copy fields in place (same verbatim rule as the constructor).
        // Cross-model reads = @kosDependency + computed getters over container indexes.
    }
    
    <% if (hasFutureSupport) { %>
    /**
     * Placeholder method for Future operations
     * Replace this with your actual long-running operation
     */
    @kosFuture()
    async performLongRunningOperation(): Promise<void> {
        // TODO: Implement your long-running operation here
        // This method should use a service that returns a Future for progress tracking
        
        this.logger.debug(`Starting long-running operation for ${this.id}`);
       
        
        // Placeholder that doesn't actually do anything
        await new Promise(resolve => setTimeout(resolve, 1000));
        
        this.logger.debug(`Completed long-running operation for ${this.id}`);
    }
    <% } %>
    
    <% if (isCompleteFuture) { %>
    /**
     * Optional: Custom Future update handling
     * Called whenever the Future state changes (progress, status, completion, etc.)
     */
    onFutureUpdate?(update: IFutureModel<<%= nameProperCase %>OperationProgress>): void {
        // Add custom Future update logic here
        // Examples:
        // - Log progress milestones
        // - Update derived state based on progress
        // - Handle specific error conditions
        // - Trigger notifications at certain thresholds
        
        this.logger.debug(`Future update for ${this.id}:`, {
            progress: update.progress,
            status: update.status,
            endState: update.endState,
            // Access typed progress data:
            stage: update.clientData?.stage,
            percentComplete: update.clientData?.percentComplete
        });
    }
    <% } %>
    
    // -------------------LIFECYCLE----------------------------
    

    async init(): Promise<void> {
        this.logger.debug(`initializing <%= nameLowerCase %> ${this.id}` );
    }


    async load(): Promise<void> {
        this.logger.debug(`loading <%= nameLowerCase %> ${this.id}`);
    }



}

export const <%= nameProperCase %> = <%= nameProperCase %>ModelImpl.Registration;

