import { create } from 'zustand';

interface EvaluationTaskState {
    query: any;
    listLoading: boolean;
    list: any[];
    page: {
        pageNum: number;
        pageSize: number;
        total: number;
    };
}

interface EvaluationTaskActions {
    setQuery: (query: any) => void;
    setListLoading: (loading: boolean) => void;
    setList: (list: any[]) => void;
    setPage: (page: any) => void;
}

export type EvaluationTaskStore = EvaluationTaskState & EvaluationTaskActions & {
    fetchEvaluationTaskList: () => Promise<void>;
};

const initialState: EvaluationTaskState = {
    query: undefined,
    listLoading: false,
    list: [],
    page: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
    },
};

export const useEvaluationTaskStore = create<EvaluationTaskStore>((set, get) => ({
    ...initialState,
    
    setQuery: (query) => set({ query }),
    
    setListLoading: (loading) => set({ listLoading: loading }),
    
    setList: (list) => set({ list }),
    
    setPage: (page) => set({ page }),
    
    fetchEvaluationTaskList: async () => {
        set({ listLoading: true });
        try {
            const { query, page } = get();
            // TODO: 调用 API 获取评估任务列表
            set({ list: [], page: { ...page, total: 0 } });
        } catch (error) {
            console.error('获取评估任务列表失败:', error);
        } finally {
            set({ listLoading: false });
        }
    },
}));

export default useEvaluationTaskStore;
