// tools/create-spec-tech/section-builders.ts — Platform-specific FICHA-TECNICA section builders
// Extracted from create-spec-tech.ts to stay within the 400-line file budget.
/**
 * SPEC-013: Generate mobile architecture guidance for the FICHA-TECNICA.
 * Returns implementation guidance based on the detected mobile architecture pattern.
 */
function getMobileArchGuidance(mobileArch) {
    const guidance = {
        tca: 'Implementar con Reducer + State + Action en ComposableArchitecture',
        mvvm: 'Implementar con @Observable / ObservableObject + @StateObject',
        viper: 'Implementar con View + Interactor + Presenter + Entity + Router',
        'clean-swift': 'Implementar con Scene (VC + Interactor + Presenter + Router + Worker)',
        mvi: 'Implementar con sealed class State/Event/Effect + ViewModel',
        'clean-architecture': 'Implementar con UseCases + Repository interfaces + mappers por capa',
    };
    return guidance[mobileArch];
}
/**
 * SPEC-013: Generate mobile-specific FICHA-TECNICA sections.
 */
export function getMobileArchitectureSections(spec, knowledge) {
    if (spec.target !== 'ios' && spec.target !== 'android') {
        return [];
    }
    const lines = ['## Mobile Architecture', ''];
    const mobileArch = knowledge?.apps.find((app) => (spec.target === 'ios' &&
        (app.mobilePlatform === 'ios' ||
            app.framework === 'swiftui' ||
            app.framework === 'uikit')) ||
        (spec.target === 'android' &&
            (app.mobilePlatform === 'android' ||
                app.framework === 'compose' ||
                app.framework === 'xml-views')))?.mobileArch;
    if (mobileArch) {
        const guidance = getMobileArchGuidance(mobileArch);
        lines.push(`**Pattern:** ${mobileArch}`);
        lines.push(`**Implementation guidance:** ${guidance}`);
        lines.push('');
    }
    if (spec.target === 'ios') {
        lines.push('**iOS Sections:**');
        lines.push('- Screens / Views');
        lines.push('- Navigation flow');
        lines.push('- State management (SwiftUI/@State vs UIKit/delegates)');
        lines.push('- Lifecycle methods');
        lines.push('');
    }
    if (spec.target === 'android') {
        lines.push('**Android Sections:**');
        lines.push('- Composables / Fragments');
        lines.push('- Navigation (NavController)');
        lines.push('- ViewModel + StateFlow');
        lines.push('');
    }
    return lines;
}
/**
 * SPEC-014b: Generate desktop-specific FICHA-TECNICA sections.
 * Adds IPC pattern, distribution targets, and framework-specific implementation notes.
 */
export function getDesktopArchitectureSections(spec, knowledge) {
    if (knowledge?.projectCategory !== 'desktop') {
        return [];
    }
    const framework = knowledge.framework?.toLowerCase() ?? '';
    const lines = ['## Desktop Architecture', ''];
    if (framework === 'electron') {
        lines.push('**Framework:** Electron (Chromium + Node.js)');
        lines.push('');
        lines.push('**IPC Pattern (contextBridge — safe/recommended):**');
        lines.push('```typescript');
        lines.push('// preload.ts');
        lines.push('import { contextBridge, ipcRenderer } from "electron";');
        lines.push('contextBridge.exposeInMainWorld("api", {');
        lines.push('  // handler exposed to renderer — add methods here');
        lines.push('  invoke: (channel: string, ...args: unknown[]) => ipcRenderer.invoke(channel, ...args),');
        lines.push('});');
        lines.push('```');
        lines.push('');
        lines.push('**IPC Handler (main process):**');
        lines.push('```typescript');
        lines.push('// main.ts');
        lines.push('ipcMain.handle("channel-name", async (_event, ...args) => {');
        lines.push('  // handle filesystem, shell, clipboard — NEVER in renderer');
        lines.push('  return result;');
        lines.push('});');
        lines.push('```');
        lines.push('');
        lines.push('**Security Requirements:**');
        lines.push('- `contextIsolation: true` — ALWAYS (mandatory)');
        lines.push('- `nodeIntegration: false` — ALWAYS (mandatory in production)');
        lines.push('- `sandbox: true` — recommended (Electron 20+ default)');
        lines.push('- CSP defined in `<meta>` or via `webRequest.onHeadersReceived`');
        lines.push('');
    }
    else if (framework === 'tauri') {
        lines.push('**Framework:** Tauri (Rust backend + WebView frontend)');
        lines.push('');
        lines.push('**Tauri Commands:**');
        lines.push('```rust');
        lines.push('// src-tauri/src/commands.rs');
        lines.push('#[tauri::command]');
        lines.push('pub async fn command_name(param: String) -> Result<String, String> {');
        lines.push('  // Rust implementation — system access here');
        lines.push('  Ok(format!("Result: {}", param))');
        lines.push('}');
        lines.push('```');
        lines.push('');
        lines.push('**Frontend Invocation:**');
        lines.push('```typescript');
        lines.push('import { invoke } from "@tauri-apps/api/core";');
        lines.push('const result = await invoke<string>("command_name", { param: "value" });');
        lines.push('```');
        lines.push('');
        lines.push('**Register command in main.rs:**');
        lines.push('```rust');
        lines.push('.invoke_handler(tauri::generate_handler![commands::command_name])');
        lines.push('```');
        lines.push('');
    }
    else if (framework === 'dotnet') {
        lines.push('**Framework:** .NET Desktop');
        lines.push('');
        lines.push('**UI Framework Detection:**');
        lines.push('- WPF: `<UseWPF>true</UseWPF>` in .csproj → MVVM pattern');
        lines.push('- WinForms: `<UseWindowsForms>true</UseWindowsForms>` → code-behind pattern');
        lines.push('- MAUI: `<UseMaui>true</UseMaui>` → cross-platform (Windows/macOS/iOS/Android)');
        lines.push('- Avalonia: `Avalonia` PackageReference → cross-platform MVVM');
        lines.push('');
        lines.push('**For WPF/Avalonia — MVVM Pattern:**');
        lines.push('- ViewModel inherits from `ObservableObject` (CommunityToolkit.Mvvm)');
        lines.push('- Commands via `[RelayCommand]` attribute');
        lines.push('- Lists via `ObservableCollection<T>` (triggers UI refresh)');
        lines.push('- XAML bindings: `{Binding PropertyName}`');
        lines.push('');
    }
    // MAUI multi-platform parity criteria
    const stack = knowledge.stack.map((s) => s.toLowerCase());
    if (stack.some((s) => s.includes('maui'))) {
        lines.push('**MAUI Cross-Platform Parity:**');
        lines.push('- Target platforms: Windows, macOS, iOS, Android');
        lines.push('- Mark platform-specific features with `#if WINDOWS`, `#if ANDROID`, etc.');
        lines.push('- Define parity criteria per feature: which platforms must support it');
        lines.push('- Platform-unavailable features: use `DeviceInfo.Platform` guard at runtime');
        lines.push('');
    }
    if (spec.tags.some((t) => t.toLowerCase().includes('release')) || spec.type === 'infra') {
        lines.push('**Distribution Targets:**');
        if (framework === 'electron') {
            lines.push('- Windows: NSIS installer or Squirrel (auto-update) + Authenticode signing');
            lines.push('- macOS: DMG or PKG + Developer ID + notarization');
            lines.push('- Linux: AppImage + deb + snap');
        }
        else if (framework === 'tauri') {
            lines.push('- Windows: MSI or NSIS + code signing');
            lines.push('- macOS: DMG + notarization (mandatory for outside App Store)');
            lines.push('- Linux: AppImage + deb + rpm');
        }
        lines.push('');
    }
    return lines;
}
//# sourceMappingURL=section-builders.js.map