mirrored_repositories/Interview-Tasks/MusicApp/lib
import 'package:get/get.dart';
import 'package:musicapp/Services/global_service.dart';

mixin ApiClient{
  final globalService = Get.find<GlobalService>();
  late String baseUrl;

  String getBaseUrl(String path) {
    if (!path.endsWith('/')) {
      path += '/';
    }
    if (path.startsWith('/')) {
      path = path.substring(1);
    }
    if (!baseUrl.endsWith('/')) {
      return baseUrl + '/' + path;
    }
    return baseUrl + path;
  }

  String getApiBaseUrl(String path) {
   
    String _apiPath = globalService.global.value.apiPath!;
    if (path.startsWith('/')) {
      return getBaseUrl(_apiPath) + path.substring(1);
    }
    return getBaseUrl(_apiPath) + path;
  }

  Uri getApiBaseUri({String path = ''}) {
    // Get.log('Base URL: ${getApiBaseUrl(path)}');
    return Uri.parse(getApiBaseUrl(path));
  }

  Uri getBaseUri(String path) {
    return Uri.parse(getBaseUrl(path));
  }

  void printUri(StackTrace stackTrace, Uri uri) {
    // Get.log(CustomTrace(stackTrace, message: uri.toString()).toString());
  }
}