import 'package:dio/dio.dart';
import '../../../../core/config/api_endpoints.dart';

/// Remote datasource for account settings against the IT0 backend API.
class SettingsRemoteDatasource {
  final Dio _dio;

  SettingsRemoteDatasource(this._dio);

  /// Fetches the current user's account info (displayName, email).
  Future<Map<String, dynamic>> getAccount() async {
    final response = await _dio.get(ApiEndpoints.adminAccount);
    return response.data as Map<String, dynamic>;
  }

  /// Updates the current user's display name.
  Future<Map<String, dynamic>> updateAccount(String displayName) async {
    final response = await _dio.put(
      ApiEndpoints.adminAccount,
      data: {'displayName': displayName},
    );
    return response.data as Map<String, dynamic>;
  }

  /// Changes the current user's password.
  /// Returns `{success: true}` or `{success: false, message: ...}`.
  Future<Map<String, dynamic>> changePassword({
    required String currentPassword,
    required String newPassword,
  }) async {
    final response = await _dio.put(
      ApiEndpoints.adminAccountPassword,
      data: {
        'currentPassword': currentPassword,
        'newPassword': newPassword,
      },
    );
    return response.data as Map<String, dynamic>;
  }
}
