/// Use case: Envoyer un message
library send_message;

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 SendMessage {
  final MessagingRepository repository;

  SendMessage(this.repository);

  Future<Either<Failure, Message>> call({
    required String conversationId,
    required String content,
    List<String>? attachments,
    MessagePriority priority = MessagePriority.normal,
  }) async {
    // Validation
    if (content.trim().isEmpty) {
      return Left(ValidationFailure('Le message ne peut pas être vide'));
    }

    return await repository.sendMessage(
      conversationId: conversationId,
      content: content,
      attachments: attachments,
      priority: priority,
    );
  }
}
