import apiClient, {baseUrl} from "./apiClient";
import * as FileSystem from 'expo-file-system';
import {
    DownloadProgressData,
    FileSystemDownloadResult,
    FileSystemNetworkTaskProgressCallback
} from "expo-file-system";


const router = '/application';
const api_key = 'AF9A20DD9264C134CDA0ADACED834368';
const applicationApi = {
    getVersion: async (name: string): Promise<{ 'latest_version': string }> => {
        let response = await apiClient.get(`${router}/${name}/version`, {headers: {Authorization: api_key}});
        return response.data;
    },
    download: async (fileUri: string, name: string, version: string, callback: FileSystemNetworkTaskProgressCallback<DownloadProgressData>): Promise<FileSystemDownloadResult | undefined> => {
        return FileSystem.createDownloadResumable(`${baseUrl}${router}/${name}/download/${version}`, fileUri, {headers: {Authorization: api_key}}, callback).downloadAsync();
    }
}

export default applicationApi;