import { CreateOrModifyKnowledgeLibApiParams } from '@/apis';

// 知识库列表记录类型 - 匹配实际 API 返回字段
export type Record = {
    [x: string]: any;
    knowledgeId: string,      // 知识库 ID
    name: string,             // 知识库名称
    length: string | number,  // 使用空间 (如 '0.28M' 或 '--')
    wordNum: string | number, // 字符数量
    documentSize: string | number, // 文件数量
    sliceCount: string | number,   // 切片数量
    isOpen: number,           // 是否公开 (1=公开，0=私有)
    createTime: string,       // 创建时间
    updateTime: string,       // 更新时间
    createBy: string,         // 创建者 ID
    maintainers?: string[],   // 维护者 ID 列表
    maintainerNames?: string[], // 维护者姓名列表
};

// 定义状态
export type State = {
    listLoading: boolean,
    list: Record[],
    infoModalId: string,
    classificationType?: string,
    name?: string,
    infoModalOpen: boolean,
    page: {
        pageNum: number,
        pageSize: number,
        total: number,
    },
};

// 只读状态
export type ReadonlyState = Readonly<State>;

// 修改状态
export type StateAction = {
    setListLoading: (loading: State['listLoading']) => void,
    setList: (list: State['list']) => void,
    setInfoModalId: (id: State['infoModalId']) => void,
    setInfoModalOpen: (open: State['infoModalOpen']) => void,
    setPage: (page: State['page']) => void,
    setClassificationType: (data?: string) => void,
    setName: (name?: string) => void,
};

// 仓库类型
export type KnowledgeLibListStore = {
    state: ReadonlyState,
    onChangePagination: (pageNum: number, pageSize: number) => Promise<any>,
    onClickCreate: () => void,
    onClickModify: (knowledgeId: string) => void,
    infoModalOnClickConfirm: (knowledgeId: string, data: CreateOrModifyKnowledgeLibApiParams) => Promise<any>,
    infoModalOnClickCancel: () => void,
    onClickDelete: (knowledgeId: string) => Promise<any>,
    init: () => Promise<any>,
    reset: () => void,
    handleModeChange: (data:State['classificationType']) => void,
    handleNameChange: (name?: string) => void,
    handFetchExportKnowledgeSliceExport: (record?: any) => void,
    exportKnowledgeMarkDown: (record: any) => Promise<void>,
    exportKnowledgeFile: (record: any) => Promise<void>,
};