/// Use case: Rejeter une transaction
library reject_transaction;

import 'package:dartz/dartz.dart';
import 'package:injectable/injectable.dart';
import '../../../../core/error/failures.dart';
import '../entities/transaction_approval.dart';
import '../repositories/finance_workflow_repository.dart';

@lazySingleton
class RejectTransaction {
  final FinanceWorkflowRepository repository;

  RejectTransaction(this.repository);

  Future<Either<Failure, TransactionApproval>> call({
    required String approvalId,
    required String reason,
  }) async {
    if (approvalId.isEmpty) {
      return Left(ValidationFailure('ID approbation requis'));
    }

    if (reason.trim().isEmpty) {
      return Left(ValidationFailure('Raison du rejet requise'));
    }

    return await repository.rejectTransaction(
      approvalId: approvalId,
      reason: reason,
    );
  }
}
