/// Use case: Récupérer les messages d'une conversation
library get_messages;

import 'package:dartz/dartz.dart';
import 'package:injectable/injectable.dart';
import '../../../../core/error/failures.dart';
import '../entities/message.dart';
import '../repositories/messaging_repository.dart';

@lazySingleton
class GetMessages {
  final MessagingRepository repository;

  GetMessages(this.repository);

  Future<Either<Failure, List<Message>>> call({
    required String conversationId,
    int? limit,
    String? beforeMessageId,
  }) async {
    if (conversationId.isEmpty) {
      return Left(ValidationFailure('ID conversation requis'));
    }

    return await repository.getMessages(
      conversationId: conversationId,
      limit: limit,
      beforeMessageId: beforeMessageId,
    );
  }
}
