import {
    uploadSingleFile,
    downloadFile,
} from '@/services/api_uploadfile'

export default {
    namespace: 'uploadfile',
    state: {
        uploadFile: {
            datarecord: null
        },
        fileList: null
    },
    effects: {
        *upload_single_file({ payload, callback }, { call, put }) {
            const response = yield call(uploadSingleFile, payload)
            yield put({
                type: 'uploadSingleFile',
                payload: response
            })

            if (callback) callback(response)
        },
        *download_file({ payload, callback }, { call, put }) {
            const response = yield call(downloadFile, payload)
            yield put({
                type: 'downloadFile',
                payload: response
            })

            if (callback) callback(response)
        },
    },
    reducers: {
        uploadSingleFile(state, action) {
            return {
                ...state,
                uploadFile: action.payload
            }
        },
        downloadFile(state, action) {
            return {
                ...state,
                fileList: action.payload
            }
        },
    }
}
