import { create } from 'zustand';
import { query } from '@/modules/query';
import { message } from '@/modules/message';
type AllFileStat = {
  list?: {
    name: string;
    lastModified: number;
    etag: string;
    size: number;
  }[];
  total?: number;
  size?: number;
  sizeMb?: number;
};
type FileStat = {
  stat: AllFileStat;
  setStat: (stat: AllFileStat) => void;
  getFileStat: () => Promise<void>;
};

export const useFileStat = create<FileStat>((set) => ({
  stat: {},
  setStat: (stat) => set({ stat }),
  getFileStat: async () => {
    // 获取所有文件统计信息
    const res = await query.post({
      path: 'file',
      key: 'me-all-file-stat',
    });
    if (res.code === 200) {
      set({ stat: res.data });
    } else {
      message.error(res.message || 'Request failed');
    }
  },
}));
