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

import '../../nextcloud_ocs.dart';
import '../talk_api.dart';
import 'create_room_params.dart';
import 'create_room_response.dart';

class CreateRoom extends TalkApi<CreateRoomResponse> {
  CreateRoomParams params;

  CreateRoom(this.params) : super('v4/room', params);

  @override
  CreateRoomResponse assemble(String raw) =>
      CreateRoomResponse.fromJson(NextcloudOcs.decode(raw));

  @override
  Future<Response>? request(
    Uri uri,
    Object? body,
    Map<String, String>? headers,
  ) {
    if (body is CreateRoomParams) {
      return http.post(
        uri,
        headers: headers,
        body: body.toJson().map(
          (key, value) => MapEntry(key, value.toString()),
        ),
      );
    }

    return null;
  }
}
