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

import '../../nextcloud_ocs.dart';
import '../talk_api.dart';
import 'get_shared_items_response.dart';

/// Fetches the messages that shared an item of a given [objectType] in a chat
/// (Talk's `GET /chat/{token}/share`). Paginated via [lastKnownMessageId] using
/// the `X-Chat-Last-Given` response header (see
/// [GetSharedItemsResponse.lastGivenMessageId]).
///
/// Known [objectType]s: `media`, `file`, `audio`, `voice`, `location`,
/// `deckcard`, `recording`, `other`.
class GetSharedItems extends TalkApi<GetSharedItemsResponse> {
  GetSharedItems(
    String token, {
    required String objectType,
    int limit = 20,
    int? lastKnownMessageId,
  }) : super(
         'v1/chat/$token/share',
         null,
         getParameters: {
           'objectType': objectType,
           'limit': limit,
           'lastKnownMessageId': ?lastKnownMessageId,
         },
       );

  @override
  GetSharedItemsResponse assemble(String raw) =>
      GetSharedItemsResponse.fromOcs(NextcloudOcs.decode(raw));

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