import { create } from 'zustand'

interface UploadState {
  file: File | null
  taskId: string | null
  fileName: string
  fileSize: number
  isUploading: boolean
  uploadProgress: number
  error: string | null

  setFile: (file: File | null) => void
  setTaskId: (taskId: string | null) => void
  setFileName: (name: string) => void
  setFileSize: (size: number) => void
  setIsUploading: (isUploading: boolean) => void
  setUploadProgress: (progress: number) => void
  setError: (error: string | null) => void
  reset: () => void
}

export const useUploadStore = create<UploadState>((set) => ({
  file: null,
  taskId: null,
  fileName: '',
  fileSize: 0,
  isUploading: false,
  uploadProgress: 0,
  error: null,

  setFile: (file) => set({ file }),
  setTaskId: (taskId) => set({ taskId }),
  setFileName: (fileName) => set({ fileName }),
  setFileSize: (fileSize) => set({ fileSize }),
  setIsUploading: (isUploading) => set({ isUploading }),
  setUploadProgress: (uploadProgress) => set({ uploadProgress }),
  setError: (error) => set({ error }),
  reset: () =>
    set({
      file: null,
      taskId: null,
      fileName: '',
      fileSize: 0,
      isUploading: false,
      uploadProgress: 0,
      error: null,
    }),
}))