import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:syncrow_app/features/app_layout/model/space_model.dart'; import 'package:syncrow_app/features/auth/model/user_model.dart'; import 'package:syncrow_app/features/devices/model/room_model.dart'; import 'package:syncrow_app/services/api/api_links_endpoints.dart'; import 'package:syncrow_app/services/api/http_service.dart'; class SpacesAPI { static final HTTPService _httpService = HTTPService(); static Future> getUnitsByUserId() async { var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey); final response = await _httpService.get( path: "${ApiEndpoints.unitUser}$uuid", showServerMessage: false, expectedResponseModel: (json) => SpaceModel.fromJsonList(json), ); return response; } static Future> getRoomsBySpaceId(String unitId) async { final response = await _httpService.get( path: "${ApiEndpoints.unitChild}$unitId", queryParameters: {"page": 1, "pageSize": 10}, showServerMessage: false, expectedResponseModel: (json) { List rooms = []; for (var room in json['children']) { rooms.add(RoomModel.fromJson(room)); } return rooms; }, ); return response; } static Future generateInvitationCode( String unitId, ) async { final response = await _httpService.get( path: ApiEndpoints.invitationCode.replaceAll('{unitUuid}', unitId), showServerMessage: false, expectedResponseModel: (json) => json['invitationCode'], ); return response; } static Future joinUnit( Map body, ) async { final response = await _httpService.post( path: ApiEndpoints.verifyInvitationCode, showServerMessage: false, body: body, expectedResponseModel: (json) => json['success'], ); return response; } }