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

import '../talk_api.dart';
import 'set_read_marker_params.dart';

class SetReadMarker extends TalkApi {
  String chatToken;
  bool readState;
  SetReadMarkerParams? setReadMarkerParams;

  SetReadMarker(this.chatToken, this.readState, {this.setReadMarkerParams})
    : super(
        'v1/chat/$chatToken/read',
        null,
        getParameters: setReadMarkerParams?.toJson(),
      ) {
    if (readState) assert(setReadMarkerParams?.lastReadMessage != null);
  }

  @override
  Null assemble(String raw) => null;

  @override
  Future<Response> request(
    Uri uri,
    Object? body,
    Map<String, String>? headers,
  ) => readState ? http.post(uri, headers: headers) : http.delete(uri, headers: headers);
}
