import { HttpMethod } from "@limetech/lime-web-components";
const CORE_API_PATH = 'api/v1';
const FILE_PATH = 'file';
const FIFTY = 50;
const THOUSAND_BYTES = 1024;
export const MAX_FILE_SIZE = FIFTY * THOUSAND_BYTES * THOUSAND_BYTES; // 50 MB
export class FileUpload {
    constructor(file, http) {
        this.file = file;
        this.http = http;
        this.uploadCancelled = false;
        this.getUrl = (fileid) => {
            return `${CORE_API_PATH}/${FILE_PATH}/${fileid !== null && fileid !== void 0 ? fileid : ''}`;
        };
    }
    async initialize() {
        this.uploadService = await this.http.createFileUpload(HttpMethod.Post, this.getUrl(), this.file);
        if (this.progressCallback) {
            this.uploadService.onProgress = this.progressCallback;
        }
    }
    async upload() {
        return this.uploadService.upload();
    }
    getFileName() {
        return this.file.name;
    }
    cancel() {
        this.uploadService.cancel();
        this.uploadCancelled = true;
    }
    set onProgress(callback) {
        this.progressCallback = callback;
        if (this.uploadService) {
            this.uploadService.onProgress = callback;
        }
    }
}
