import 'package:nextcloud/nextcloud.dart';

import '../../../model/accountData.dart';
import '../../../model/endpointData.dart';
import '../../apiRequest.dart';
import '../../apiResponse.dart';

abstract class WebdavApi<T> extends ApiRequest {
  T genericParams;

  WebdavApi(this.genericParams) {
    establishWebdavConnection();
  }

  Future<ApiResponse> run();

  static Future<WebDavClient> webdav = establishWebdavConnection();
  static Future<String> webdavConnectString = buildWebdavConnectString();

  static Future<WebDavClient> establishWebdavConnection() async => NextcloudClient(Uri.parse('https://${EndpointData().nextcloud().full()}'), password: AccountData().getPassword(), loginName: AccountData().getUsername()).webdav;

  static Future<String> buildWebdavConnectString() async => 'https://${AccountData().buildHttpAuthString()}@${EndpointData().nextcloud().full()}/remote.php/dav/files/${AccountData().getUsername()}/';
}
