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

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

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

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
}

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

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


// ========== API 模块 ==========
declare module 'shared/api' {
    import type { AxiosResponse, AxiosRequestConfig } from 'axios'
    
    interface ApiInstance {
        get<T = any>(url: string,data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>
        post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>
        put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>
        delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>
        uploadPut<T = any>(url: string, data: FormData, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>
    }
    
    export const api: ApiInstance
    export const TokenManager: 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
}

// ============ types模块 ==================
declare module 'shared/types' {
    // 基础类型
    export interface OrderField {
        field: string
        order: 'ASC' | 'DESC'
    }

    export interface BaseDTO {
        optsn?: string
        creator?: string
        updater?: string
        deptPath?: string
        remark?: string
        createTime?: string
        updateTime?: string
        deleteTime?: string
        deleted?: boolean
        limit?: number
        startTime?: string
        endTime?: string
        orderFields?: OrderField[]
    }

    export interface BaseVO extends BaseDTO {
        id?: string
    }

    // 重新导出 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,
        CreateChatParam,
        StopChatParam,
        CommentMessageParam,
        ChatListParam,
        ChatMessageListParam,
        SSEMessageData,
        SSECallbacks,
        SSETask
    } from '../../../shared/src/types/ai'

    // 重新导出 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>
}
