/**
 * Shared Module Federation 类型声明
 * 用于 TypeScript 识别远程模块
 */

// ========== 组件模块 ==========
declare module 'shared/components' {
    export const FileUpload: any
    export const DynamicFormItem: any
    export const IframeView: any
}

declare module 'shared/components/FileUpload' {
    import { DefineComponent } from 'vue'
    const FileUpload: DefineComponent<{}, {}, any>
    export default FileUpload
}

declare module 'shared/components/DynamicFormItem' {
    import { DefineComponent } from 'vue'
    const DynamicFormItem: DefineComponent<{}, {}, any>
    export default DynamicFormItem
}

declare module 'shared/components/iframe/IframeView.vue' {
    import { DefineComponent } from 'vue'
    const IframeView: DefineComponent<{}, {}, any>
    export default IframeView
}

// ========== API 模块 ==========
declare module 'shared/api' {
    export const api: any
    export const TokenManager: any
    export const authAPI: any
    export const fileAPI: any
    export const workcaseAPI: any
}

declare module 'shared/api/auth' {
    export const authAPI: any
}

declare module 'shared/api/file' {
    export const fileAPI: any
}

declare module 'shared/api/ai' {
    export const agentAPI: any
    export const aiKnowledgeAPI: any
    export const aiChatAPI: any
}

declare module 'shared/api/workcase' {
    export const workcaseAPI: any
}

// ============ types模块 ==================
declare module 'shared/types' {
    import type { BaseDTO } from '../../../shared/src/types/base'
    
    // 重新导出 base
    export type { BaseDTO }
    
    // 重新导出 response
    export type { ResultDomain } from '../../../shared/src/types/response'
    
    // 重新导出 page
    export type { PageDomain, PageParam, PageRequest } from '../../../shared/src/types/page'
    
    // 重新导出 auth
    export type { LoginParam, LoginDomain } from '../../../shared/src/types/auth'
    
    // 重新导出 sys
    export type { SysUserVO, SysConfigVO, TbSysViewDTO } from '../../../shared/src/types/sys'
    
    // 重新导出 file
    export type { TbSysFileDTO } from '../../../shared/src/types/file'
    
    // 重新导出 ai
    export type { 
        TbKnowledge, 
        TbKnowledgeFile,
        TbAgent,
        PromptCard,
        TbChat,
        TbChatMessage,
        DifyFileInfo,
        ChatPrepareData,
        StopChatParams,
        CommentMessageParams
    } from '../../../shared/src/types/ai'
    
    // 重新导出 workcase
    export type { 
        TbWorkcaseDTO, 
        TbWorkcaseProcessDTO, 
        TbWorkcaseDeviceDTO 
    } from '../../../shared/src/types/workcase'
    
    // 重新导出 menu
    export type { MenuItem, toMenuItem, toMenuItems } from '../../../shared/src/types/menu'
}

// ================ utils工具 ==========================
declare module 'shared/utils' {
    export const initAesEncrypt: any
    export const getAesInstance: any
    export const formatFileSize: any
    export const isImageFile: any
    export const getFileTypeIcon: any
    export const isValidFileType: any
    export const getFilePreviewUrl: any
}

declare module 'shared/utils/route' {
    import { RouteRecordRaw } from 'vue-router'
    import type { TbSysViewDTO } from 'shared/types'
    
    export interface RouteGeneratorConfig {
        layoutMap: Record<string, () => Promise<any>>
        viewLoader: (componentPath: string) => (() => Promise<any>) | null
        staticRoutes?: RouteRecordRaw[]
        notFoundComponent?: () => Promise<any>
    }
    
    export interface GenerateSimpleRoutesOptions {
        asRootChildren?: boolean
        iframePlaceholder?: () => Promise<any>
        verbose?: boolean
    }
    
    export function generateRoutes(
        views: TbSysViewDTO[], 
        config: RouteGeneratorConfig
    ): RouteRecordRaw[]
    
    export function generateSimpleRoutes(
        views: TbSysViewDTO[],
        config: RouteGeneratorConfig,
        options?: GenerateSimpleRoutesOptions
    ): RouteRecordRaw[]
    
    export function buildMenuTree(
        views: TbSysViewDTO[], 
        staticRoutes?: RouteRecordRaw[]
    ): TbSysViewDTO[]
    
    export function filterMenusByPermissions(
        views: TbSysViewDTO[], 
        permissions: string[]
    ): TbSysViewDTO[]
    
    export function findMenuByPath(
        views: TbSysViewDTO[], 
        path: string
    ): TbSysViewDTO | null
    
    export function getMenuPath(
        views: TbSysViewDTO[], 
        targetViewId: string
    ): TbSysViewDTO[]
    
    export function getFirstAccessibleMenuUrl(
        views: TbSysViewDTO[]
    ): string | null
    
    export function loadViewsFromStorage(
        storageKey?: string,
        viewsPath?: string
    ): TbSysViewDTO[] | null
}

declare module 'shared/utils/device' {
    export enum DeviceType {
        MOBILE = 'mobile',
        DESKTOP = 'desktop'
    }
    
    export function getDeviceType(): DeviceType
    export function isMobile(): boolean
    export function isDesktop(): boolean
    export function useDevice(): any
}

// ========== Layouts 布局模块 ==========
declare module 'shared/layouts' {
    import { DefineComponent } from 'vue'
    
    export const BlankLayout: DefineComponent<{}, {}, any>
    export const SubSidebarLayout: DefineComponent<{}, {}, any>
}
