package abk:lifecycle@0.2.0;

/// Template lifecycle management interface
/// Handles template loading, rendering, and task classification
interface adapter {
    /// Template variable for substitution
    record template-variable {
        /// Variable name (without braces)
        key: string,
        /// Variable value
        value: string,
    }

    /// Template section extracted from markdown
    record template-section {
        /// Section name (from ## Header)
        name: string,
        /// Section content
        content: string,
    }

    /// Error type for lifecycle operations
    record lifecycle-error {
        /// Error message
        message: string,
        /// Optional error code
        code: option<string>,
    }

    /// Task classification result
    record task-classification {
        /// Task type (bug_fix, feature, maintenance, query, fallback)
        task-type: string,
        /// Confidence score (0.0 - 1.0)
        confidence: f32,
    }

    /// Get lifecycle plugin metadata
    /// Returns JSON with name, version, supported task types, etc.
    get-lifecycle-metadata: func() -> string;

    /// Load template from embedded resources or filesystem
    /// template-name: Template identifier (e.g., "system", "task/bug_fix")
    /// Returns template content as markdown string
    load-template: func(template-name: string) -> result<string, lifecycle-error>;

    /// Render template with variable substitution
    /// template-content: Template markdown with {variable} placeholders
    /// variables: List of key-value pairs for substitution
    /// Returns rendered template content
    render-template: func(template-content: string, variables: list<template-variable>) -> string;

    /// Extract sections from markdown template
    /// template-content: Markdown content with ## Section headers
    /// Returns list of sections with names and content
    extract-sections: func(template-content: string) -> list<template-section>;

    /// Validate template variables
    /// template-content: Template to analyze
    /// Returns list of variable names found in template
    validate-template-variables: func(template-content: string) -> list<string>;

    /// Get task template path based on classification
    /// task-type: Type of task (bug_fix, feature, maintenance, query)
    /// Returns template identifier for the task type
    get-task-template-name: func(task-type: string) -> string;

    /// Classify task based on description
    /// task-description: User's task description
    /// Returns classification result with task type and confidence
    classify-task: func(task-description: string) -> result<task-classification, lifecycle-error>;

    /// Load useful commands content
    /// Returns markdown content with available tools and commands
    load-useful-commands: func() -> result<string, lifecycle-error>;

    /// Add system information to variables
    /// Returns list of system info variables (system, release, version, machine, processor)
    get-system-info-variables: func() -> list<template-variable>;
}

/// Lifecycle plugin world - template management WASM modules implement this
world lifecycle {
    export adapter;
}
