/// Use case: Envoyer un broadcast organisation
library send_broadcast;

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

  SendBroadcast(this.repository);

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

    if (content.trim().isEmpty) {
      return Left(ValidationFailure('Le message ne peut pas être vide'));
    }

    if (organizationId.isEmpty) {
      return Left(ValidationFailure('ID organisation requis'));
    }

    return await repository.sendBroadcast(
      organizationId: organizationId,
      subject: subject,
      content: content,
      priority: priority,
      attachments: attachments,
    );
  }
}
