import 'package:syncrow_app/services/api/api_links_endpoints.dart';
import 'package:syncrow_app/services/api/http_service.dart';
import 'package:syncrow_app/utils/constants/temp_const.dart';

class HomeCreation {
  static final HTTPService _httpService = HTTPService();

  static Future<Map<String, dynamic>> createCommunity(
      Map<String, String> body) async {
    try {
      final response = await _httpService.post(
        path: ApiEndpoints.addCommunity,
        body: body,
        showServerMessage: false,
        expectedResponseModel: (json) {
          return json;
        },
      );
      return response;
    } catch (e) {
      rethrow;
    }
  }

  static Future<Map<String, dynamic>> assignUserToCommunity(
      Map<String, String> body) async {
    try {
      final response = await _httpService.post(
        path: ApiEndpoints.addCommunityToUser,
        body: body,
        showServerMessage: false,
        expectedResponseModel: (json) {
          return json;
        },
      );
      return response;
    } catch (e) {
      rethrow;
    }
  }

  static Future<Map<String, dynamic>> createBuilding(
      Map<String, String> body) async {
    try {
      final response = await _httpService.post(
        path: ApiEndpoints.addBuilding,
        body: body,
        showServerMessage: false,
        expectedResponseModel: (json) {
          return json;
        },
      );
      return response;
    } catch (e) {
      rethrow;
    }
  }

  static Future<Map<String, dynamic>> assignUserToBuilding(
      Map<String, String> body) async {
    try {
      final response = await _httpService.post(
        path: ApiEndpoints.addBuildingToUser,
        body: body,
        showServerMessage: false,
        expectedResponseModel: (json) {
          return json;
        },
      );
      return response;
    } catch (e) {
      rethrow;
    }
  }

  static Future<Map<String, dynamic>> createFloor(
      Map<String, String> body) async {
    try {
      final response = await _httpService.post(
        path: ApiEndpoints.addFloor,
        body: body,
        showServerMessage: false,
        expectedResponseModel: (json) {
          return json;
        },
      );
      return response;
    } catch (e) {
      rethrow;
    }
  }

  static Future<Map<String, dynamic>> assignUserToFloor(
      Map<String, String> body) async {
    try {
      final response = await _httpService.post(
        path: ApiEndpoints.addBuildingToUser,
        body: body,
        showServerMessage: false,
        expectedResponseModel: (json) {
          return json;
        },
      );
      return response;
    } catch (e) {
      rethrow;
    }
  }

  static Future<Map<String, dynamic>> createUnit(
      Map<String, String> body) async {
    try {
      final response = await _httpService.post(
        path: ApiEndpoints.addUnit,
        body: body,
        showServerMessage: false,
        expectedResponseModel: (json) {
          return json;
        },
      );
      return response;
    } catch (e) {
      rethrow;
    }
  }

  static Future<Map<String, dynamic>> assignUserToUnit(
      Map<String, String> body) async {
    try {
      final response = await _httpService.post(
        path: ApiEndpoints.addUnitToUser,
        body: body,
        showServerMessage: false,
        expectedResponseModel: (json) {
          return json;
        },
      );
      return response;
    } catch (e) {
      rethrow;
    }
  }

  static Future<Map<String, dynamic>> createRoom({
    required String communityId,
    required String spaceId,
    required Map<String, String> body,
    required String projectId
  }) async {
    try {
      final fullPath = ApiEndpoints.addSubSpace
          .replaceAll('{communityUuid}', communityId)
          .replaceAll('{spaceUuid}', spaceId)
          .replaceAll('{projectUuid}', projectId);
      final response = await _httpService.post(
        path: fullPath,
        body: body,
        showServerMessage: false,
        expectedResponseModel: (json) {
          return json;
        },
      );
      return response;
    } catch (e) {
      rethrow;
    }
  }

  static Future<Map<String, dynamic>> assignUserToRoom(
      Map<String, String> body) async {
    try {
      final response = await _httpService.post(
        path: ApiEndpoints.addRoomToUser,
        body: body,
        showServerMessage: false,
        expectedResponseModel: (json) {
          return json;
        },
      );
      return response;
    } catch (e) {
      rethrow;
    }
  }
}
