import { DirectoryFilesResponse } from '@/domain/models/directories/DirectoryFilesResponse.interface';
import { http } from '@/infrastructure/http/http';
export class DirectoryFilesService {
    constructor() {
    }

    async getDirectoryListingFromServer(selected_directory : string): Promise<DirectoryFilesResponse>{
        let directory_url = process.env.VUE_APP_ROOT_API + '/filesystem/directory?path=';
            return await http.get<DirectoryFilesResponse>(directory_url + selected_directory);
    }

    async validateRegularExpression(attributes : any){
        let url = process.env.VUE_APP_ROOT_API + '/commons/validator/expression';
            return await http.post<any>(url, attributes);
    }
    async uploadFileToServer(file: File, pathToLoadFile: string = '/'): Promise<any>{
        let url = process.env.VUE_APP_ROOT_API + '/files?path=' + pathToLoadFile;
        let formData = new FormData();
        formData.append('file', file);
        return await http.postForm(url, formData);
    }
    async createFolderToServer(pathToCreateFolderToServer: string, nameNewFolder: string){
        let url = process.env.VUE_APP_ROOT_API + '/filesystem/directory?path=' + pathToCreateFolderToServer + "/" + nameNewFolder;
        let formData = new FormData();
        return await http.postForm(url, formData);
    }


}