import 'package:http/http.dart' as http;

import '../nextcloud_ocs.dart';

/// Revokes an app password server-side via
/// `DELETE /ocs/v2.php/core/apppassword`. The endpoint revokes the credential
/// the request authenticates WITH — by default the shared OCS headers (general
/// app password); pass [authorizationHeader] to revoke another one (the Talk
/// app password). Best-effort: the result is ignored — logout clears local
/// state regardless.
class DeleteAppPassword {
  final http.Client _client;

  DeleteAppPassword({http.Client? client}) : _client = client ?? http.Client();

  Future<void> run({String? authorizationHeader}) async {
    await _client.delete(
      NextcloudOcs.uri('core/apppassword'),
      headers: {
        ...NextcloudOcs.headers(),
        'Authorization': ?authorizationHeader,
      },
    );
  }
}
