Skip to main content

arolariu.Backend.Domain.Invoices.Services.Processing

arolariu.Backend.Domain.Invoices

arolariu.Backend.Domain.Invoices.Services.Processing Namespace

Classes

InvoiceProcessingService Class

This class represents the invoice processing service.

public class InvoiceProcessingService : arolariu.Backend.Domain.Invoices.Services.Processing.IInvoiceProcessingService

Inheritance System.Object 🡒 InvoiceProcessingService

Implements IInvoiceProcessingService

Constructors

InvoiceProcessingService(IInvoiceOrchestrationService, IMerchantOrchestrationService, ILoggerFactory) Constructor

Public constructor.

public InvoiceProcessingService(arolariu.Backend.Domain.Invoices.Services.Orchestration.InvoiceService.IInvoiceOrchestrationService invoiceOrchestrationService, arolariu.Backend.Domain.Invoices.Services.Orchestration.MerchantService.IMerchantOrchestrationService merchantOrchestrationService, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory);

Parameters

invoiceOrchestrationService IInvoiceOrchestrationService

merchantOrchestrationService IMerchantOrchestrationService

loggerFactory Microsoft.Extensions.Logging.ILoggerFactory

Methods

InvoiceProcessingService.AddMetadataToInvoice(IDictionary<string,object>, Guid, Nullable<Guid>, CancellationToken) Method

Adds or merges metadata entries into an invoice's metadata dictionary.

public System.Threading.Tasks.Task AddMetadataToInvoice(System.Collections.Generic.IDictionary<string,object> metadata, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

metadata System.Collections.Generic.IDictionary<System.String,System.Object>

Key/value pairs to add or overwrite.

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements AddMetadataToInvoice(IDictionary<string,object>, Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task

InvoiceProcessingService.AddProduct(Product, Guid, Nullable<Guid>, CancellationToken) Method

Adds (appends or merges) a product into an invoice's product collection.

public System.Threading.Tasks.Task AddProduct(arolariu.Backend.Domain.Invoices.DDD.ValueObjects.Products.Product product, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

product Product

Product to add.

invoiceIdentifier System.Guid

Target invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements AddProduct(Product, Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task

InvoiceProcessingService.AnalyzeInvoice(AnalysisOptions, Guid, Nullable<Guid>, CancellationToken) Method

Performs analysis / enrichment over a single invoice according to option flags.

public System.Threading.Tasks.Task AnalyzeInvoice(arolariu.Backend.Domain.Invoices.DTOs.AnalysisOptions options, System.Guid identifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

options AnalysisOptions

Directive flags specifying which enrichment steps to perform (MUST NOT be null).

identifier System.Guid

Invoice identifier.

userIdentifier System.Nullable<System.Guid>

Optional tenant / partition context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements AnalyzeInvoice(AnalysisOptions, Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task

Remarks

Behavior: Retrieves (if not already forwarded), validates and applies analysis steps (classification, normalization, tagging). Delegates deterministic enrichment to foundation analysis service; may invoke external AI/OCR via brokers indirectly in future.

Side Effects: Does not currently persist changes (future: optional persistence flag).

InvoiceProcessingService.Classify(Exception) Method

Translates any upstream orchestration-tier exception (invoice or merchant) into the matching processing-tier outer exception while preserving OTel metric recording and structured logging via the CreateAndLog* builder methods. Unknown exceptions fall through to the service tier (catch-all).

private System.Exception Classify(System.Exception exception);

Parameters

exception System.Exception

Returns

System.Exception

Remarks

Merchant orchestration validation errors are intentionally collapsed to InvoiceProcessingServiceDependencyValidationException because, from the invoice bounded context's perspective, the merchant orchestration service is a downstream dependency — its input validation failures classify as dependency-validation failures here.

InvoiceProcessingService.CreateInvoice(Invoice, Nullable<Guid>, CancellationToken) Method

Persists a new invoice aggregate (delegates persistence to foundation layer).

public System.Threading.Tasks.Task CreateInvoice(arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice invoice, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

invoice Invoice

Invoice aggregate to create (MUST NOT be null).

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements CreateInvoice(Invoice, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task

Remarks

Workflow: Validate aggregate invariants → call foundation storage → perform optional post-create enrichment (future).

InvoiceProcessingService.CreateInvoiceScan(InvoiceScan, Guid, Nullable<Guid>, CancellationToken) Method

Creates (persists) a scan resource associated with an invoice.

public System.Threading.Tasks.Task CreateInvoiceScan(arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.InvoiceScan scan, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

scan InvoiceScan

Scans data (raw / encoded representation).

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements CreateInvoiceScan(InvoiceScan, Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task

InvoiceProcessingService.CreateMerchant(Merchant, Nullable<Guid>, CancellationToken) Method

Persists a new merchant aggregate (delegates to foundation storage).

public System.Threading.Tasks.Task CreateMerchant(arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant merchant, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

merchant Merchant

Merchant aggregate.

parentCompanyId System.Nullable<System.Guid>

Optional partition / company scope.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements CreateMerchant(Merchant, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task

InvoiceProcessingService.DeleteInvoice(Guid, Nullable<Guid>, CancellationToken) Method

Deletes a single invoice (logical or physical per foundation implementation).

public System.Threading.Tasks.Task DeleteInvoice(System.Guid identifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

identifier System.Guid

Invoice identifier.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements DeleteInvoice(Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task

InvoiceProcessingService.DeleteInvoices(Guid, CancellationToken) Method

Deletes all invoices for a specified partition / user.

public System.Threading.Tasks.Task DeleteInvoices(System.Guid userIdentifier, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

userIdentifier System.Guid

Partition / user identifier (MUST NOT be empty).

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements DeleteInvoices(Guid, CancellationToken)

Returns

System.Threading.Tasks.Task

Remarks

<b>Caution:</b> Potentially expensive operation (fan‑out deletes). Backlog: replace with batch / soft-delete flag.

InvoiceProcessingService.DeleteInvoiceScan(InvoiceScan, Guid, Nullable<Guid>, CancellationToken) Method

Deletes the scan resource for an invoice.

public System.Threading.Tasks.Task DeleteInvoiceScan(arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.InvoiceScan scan, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

scan InvoiceScan

The invoice scan object

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements DeleteInvoiceScan(InvoiceScan, Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task

InvoiceProcessingService.DeleteMerchant(Guid, Nullable<Guid>, CancellationToken) Method

Deletes a merchant aggregate.

public System.Threading.Tasks.Task DeleteMerchant(System.Guid identifier, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

identifier System.Guid

Merchant id.

parentCompanyId System.Nullable<System.Guid>

Optional company / partition scope.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements DeleteMerchant(Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task

InvoiceProcessingService.DeleteMetadataFromInvoice(IEnumerable<string>, Guid, Nullable<Guid>, CancellationToken) Method

Removes specific metadata keys from an invoice.

public System.Threading.Tasks.Task DeleteMetadataFromInvoice(System.Collections.Generic.IEnumerable<string> metadataKeys, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

metadataKeys System.Collections.Generic.IEnumerable<System.String>

Keys to remove.

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements DeleteMetadataFromInvoice(IEnumerable<string>, Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task

InvoiceProcessingService.DeleteProduct(Product, Guid, Nullable<Guid>, CancellationToken) Method

Deletes a product from an invoice using the product value object.

public System.Threading.Tasks.Task DeleteProduct(arolariu.Backend.Domain.Invoices.DDD.ValueObjects.Products.Product product, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

product Product

Product instance to remove (matched by identifying fields).

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements DeleteProduct(Product, Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task

InvoiceProcessingService.DeleteProduct(string, Guid, Nullable<Guid>, CancellationToken) Method

Deletes a product from an invoice by name.

public System.Threading.Tasks.Task DeleteProduct(string productName, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

productName System.String

Product name.

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements DeleteProduct(string, Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task

InvoiceProcessingService.GetMetadataFromInvoice(Guid, Nullable<Guid>, CancellationToken) Method

Retrieves all metadata entries attached to an invoice.

public System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<string,object>> GetMetadataFromInvoice(System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements GetMetadataFromInvoice(Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<System.String,System.Object>>

InvoiceProcessingService.GetProduct(string, Guid, Nullable<Guid>, CancellationToken) Method

Retrieves a single product by name from an invoice.

public System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.ValueObjects.Products.Product> GetProduct(string productName, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

productName System.String

Product name (case sensitivity policy defined by implementation).

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements GetProduct(string, Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task<Product>

InvoiceProcessingService.GetProducts(Guid, Nullable<Guid>, CancellationToken) Method

Retrieves all products belonging to an invoice.

public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<arolariu.Backend.Domain.Invoices.DDD.ValueObjects.Products.Product>> GetProducts(System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements GetProducts(Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Product>>

InvoiceProcessingService.ReadInvoice(Guid, Nullable<Guid>, CancellationToken) Method

Retrieves a single invoice aggregate.

public System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice> ReadInvoice(System.Guid identifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

identifier System.Guid

Invoice identifier.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements ReadInvoice(Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task<Invoice>
The invoice or null / exception depending on implementation policy.

InvoiceProcessingService.ReadInvoices(Guid, CancellationToken) Method

Enumerates invoices within a partition scope.

public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice>> ReadInvoices(System.Guid userIdentifier, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

userIdentifier System.Guid

Partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements ReadInvoices(Guid, CancellationToken)

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Invoice>>

Remarks

<b>Pagination:</b> Not implemented (backlog).

InvoiceProcessingService.ReadInvoiceScans(Guid, Nullable<Guid>, CancellationToken) Method

Retrieves all scans associated with an invoice.

public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.InvoiceScan>> ReadInvoiceScans(System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements ReadInvoiceScans(Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<InvoiceScan>>

InvoiceProcessingService.ReadMerchant(Guid, Nullable<Guid>, CancellationToken) Method

Retrieves a merchant aggregate by identifier.

public System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant> ReadMerchant(System.Guid identifier, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

identifier System.Guid

Merchant id.

parentCompanyId System.Nullable<System.Guid>

Optional partition / company scope.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements ReadMerchant(Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task<Merchant>

InvoiceProcessingService.ReadMerchants(Guid, CancellationToken) Method

Enumerates merchants optionally filtered by a partition / company scope.

public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant>> ReadMerchants(System.Guid parentCompanyId, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

parentCompanyId System.Guid

Company / partition scope.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements ReadMerchants(Guid, CancellationToken)

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Merchant>>

InvoiceProcessingService.UpdateInvoice(Invoice, Guid, Nullable<Guid>, CancellationToken) Method

Replaces an existing invoice aggregate with updated state.

public System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice> UpdateInvoice(arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice updatedInvoice, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

updatedInvoice Invoice

New aggregate state.

invoiceIdentifier System.Guid

Identifier of target invoice.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements UpdateInvoice(Invoice, Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task<Invoice>
Updated invoice.

InvoiceProcessingService.UpdateMerchant(Merchant, Guid, Nullable<Guid>, CancellationToken) Method

Replaces an existing merchant aggregate with updated state.

public System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant> UpdateMerchant(arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant updatedMerchant, System.Guid identifier, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

updatedMerchant Merchant

New merchant state.

identifier System.Guid

Merchant id.

parentCompanyId System.Nullable<System.Guid>

Optional company / partition scope.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements UpdateMerchant(Merchant, Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task<Merchant>
Updated merchant.

InvoiceProcessingService.UpdateMetadataOnInvoice(IDictionary<string,object>, Guid, Nullable<Guid>, CancellationToken) Method

Upserts metadata entries on an invoice (adds new keys, overwrites existing ones).

public System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<string,object>> UpdateMetadataOnInvoice(System.Collections.Generic.IDictionary<string,object> metadata, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

metadata System.Collections.Generic.IDictionary<System.String,System.Object>

Key/value pairs to upsert.

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Implements UpdateMetadataOnInvoice(IDictionary<string,object>, Guid, Nullable<Guid>, CancellationToken)

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<System.String,System.Object>>
Updated metadata dictionary snapshot.

Interfaces

IInvoiceProcessingService Interface

Processing layer contract for performing higher-cost or multi-step domain operations (enrichment, aggregation, fan‑out mutations) over invoice and merchant aggregates.

public interface IInvoiceProcessingService

Derived
InvoiceProcessingService

Remarks

Layer Role (The Standard): Processing services encapsulate computational / transformational logic that may compose foundation services and optionally orchestration services for delegated persistence / retrieval, while remaining transport-agnostic.

Responsibilities:

  • Perform analysis / enrichment flows that are more than a simple single-service call (e.g., iterative product normalization).
  • Apply batch style or multi-entity operations (e.g., deleting all invoices for a user).
  • Isolate performance-sensitive logic (looping, projection building, in‑memory filtering) away from orchestration layer.

Exclusions: No direct broker calls (should be via foundation), no HTTP concerns, no UI mapping, no long‑running state persistence.

Partitioning:userIdentifier / parentCompanyId parameters act as tenancy / partition discriminators and MUST be propagated downstream unchanged.

Idempotency: Read operations and deletions of already non‑existent resources are idempotent; create / update operations are not inherently idempotent.

Concurrency: No optimistic concurrency yet; future enhancement may integrate version / ETag semantics.

Methods

IInvoiceProcessingService.AddMetadataToInvoice(IDictionary<string,object>, Guid, Nullable<Guid>, CancellationToken) Method

Adds or merges metadata entries into an invoice's metadata dictionary.

System.Threading.Tasks.Task AddMetadataToInvoice(System.Collections.Generic.IDictionary<string,object> metadata, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

metadata System.Collections.Generic.IDictionary<System.String,System.Object>

Key/value pairs to add or overwrite.

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task

IInvoiceProcessingService.AddProduct(Product, Guid, Nullable<Guid>, CancellationToken) Method

Adds (appends or merges) a product into an invoice's product collection.

System.Threading.Tasks.Task AddProduct(arolariu.Backend.Domain.Invoices.DDD.ValueObjects.Products.Product product, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

product Product

Product to add.

invoiceIdentifier System.Guid

Target invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task

IInvoiceProcessingService.AnalyzeInvoice(AnalysisOptions, Guid, Nullable<Guid>, CancellationToken) Method

Performs analysis / enrichment over a single invoice according to option flags.

System.Threading.Tasks.Task AnalyzeInvoice(arolariu.Backend.Domain.Invoices.DTOs.AnalysisOptions options, System.Guid identifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

options AnalysisOptions

Directive flags specifying which enrichment steps to perform (MUST NOT be null).

identifier System.Guid

Invoice identifier.

userIdentifier System.Nullable<System.Guid>

Optional tenant / partition context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task

Remarks

Behavior: Retrieves (if not already forwarded), validates and applies analysis steps (classification, normalization, tagging). Delegates deterministic enrichment to foundation analysis service; may invoke external AI/OCR via brokers indirectly in future.

Side Effects: Does not currently persist changes (future: optional persistence flag).

IInvoiceProcessingService.CreateInvoice(Invoice, Nullable<Guid>, CancellationToken) Method

Persists a new invoice aggregate (delegates persistence to foundation layer).

System.Threading.Tasks.Task CreateInvoice(arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice invoice, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

invoice Invoice

Invoice aggregate to create (MUST NOT be null).

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task

Remarks

Workflow: Validate aggregate invariants → call foundation storage → perform optional post-create enrichment (future).

IInvoiceProcessingService.CreateInvoiceScan(InvoiceScan, Guid, Nullable<Guid>, CancellationToken) Method

Creates (persists) a scan resource associated with an invoice.

System.Threading.Tasks.Task CreateInvoiceScan(arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.InvoiceScan scan, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

scan InvoiceScan

Scans data (raw / encoded representation).

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task

IInvoiceProcessingService.CreateMerchant(Merchant, Nullable<Guid>, CancellationToken) Method

Persists a new merchant aggregate (delegates to foundation storage).

System.Threading.Tasks.Task CreateMerchant(arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant merchant, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

merchant Merchant

Merchant aggregate.

parentCompanyId System.Nullable<System.Guid>

Optional partition / company scope.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task

IInvoiceProcessingService.DeleteInvoice(Guid, Nullable<Guid>, CancellationToken) Method

Deletes a single invoice (logical or physical per foundation implementation).

System.Threading.Tasks.Task DeleteInvoice(System.Guid identifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

identifier System.Guid

Invoice identifier.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task

IInvoiceProcessingService.DeleteInvoices(Guid, CancellationToken) Method

Deletes all invoices for a specified partition / user.

System.Threading.Tasks.Task DeleteInvoices(System.Guid userIdentifier, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

userIdentifier System.Guid

Partition / user identifier (MUST NOT be empty).

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task

Remarks

<b>Caution:</b> Potentially expensive operation (fan‑out deletes). Backlog: replace with batch / soft-delete flag.

IInvoiceProcessingService.DeleteInvoiceScan(InvoiceScan, Guid, Nullable<Guid>, CancellationToken) Method

Deletes the scan resource for an invoice.

System.Threading.Tasks.Task DeleteInvoiceScan(arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.InvoiceScan scan, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

scan InvoiceScan

The invoice scan object

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task

IInvoiceProcessingService.DeleteMerchant(Guid, Nullable<Guid>, CancellationToken) Method

Deletes a merchant aggregate.

System.Threading.Tasks.Task DeleteMerchant(System.Guid identifier, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

identifier System.Guid

Merchant id.

parentCompanyId System.Nullable<System.Guid>

Optional company / partition scope.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task

IInvoiceProcessingService.DeleteMetadataFromInvoice(IEnumerable<string>, Guid, Nullable<Guid>, CancellationToken) Method

Removes specific metadata keys from an invoice.

System.Threading.Tasks.Task DeleteMetadataFromInvoice(System.Collections.Generic.IEnumerable<string> metadataKeys, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

metadataKeys System.Collections.Generic.IEnumerable<System.String>

Keys to remove.

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task

IInvoiceProcessingService.DeleteProduct(Product, Guid, Nullable<Guid>, CancellationToken) Method

Deletes a product from an invoice using the product value object.

System.Threading.Tasks.Task DeleteProduct(arolariu.Backend.Domain.Invoices.DDD.ValueObjects.Products.Product product, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

product Product

Product instance to remove (matched by identifying fields).

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task

IInvoiceProcessingService.DeleteProduct(string, Guid, Nullable<Guid>, CancellationToken) Method

Deletes a product from an invoice by name.

System.Threading.Tasks.Task DeleteProduct(string productName, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

productName System.String

Product name.

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task

IInvoiceProcessingService.GetMetadataFromInvoice(Guid, Nullable<Guid>, CancellationToken) Method

Retrieves all metadata entries attached to an invoice.

System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<string,object>> GetMetadataFromInvoice(System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<System.String,System.Object>>

IInvoiceProcessingService.GetProduct(string, Guid, Nullable<Guid>, CancellationToken) Method

Retrieves a single product by name from an invoice.

System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.ValueObjects.Products.Product> GetProduct(string productName, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

productName System.String

Product name (case sensitivity policy defined by implementation).

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task<Product>

IInvoiceProcessingService.GetProducts(Guid, Nullable<Guid>, CancellationToken) Method

Retrieves all products belonging to an invoice.

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<arolariu.Backend.Domain.Invoices.DDD.ValueObjects.Products.Product>> GetProducts(System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Product>>

IInvoiceProcessingService.ReadInvoice(Guid, Nullable<Guid>, CancellationToken) Method

Retrieves a single invoice aggregate.

System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice> ReadInvoice(System.Guid identifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

identifier System.Guid

Invoice identifier.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task<Invoice>
The invoice or null / exception depending on implementation policy.

IInvoiceProcessingService.ReadInvoices(Guid, CancellationToken) Method

Enumerates invoices within a partition scope.

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice>> ReadInvoices(System.Guid userIdentifier, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

userIdentifier System.Guid

Partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Invoice>>

Remarks

<b>Pagination:</b> Not implemented (backlog).

IInvoiceProcessingService.ReadInvoiceScans(Guid, Nullable<Guid>, CancellationToken) Method

Retrieves all scans associated with an invoice.

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.InvoiceScan>> ReadInvoiceScans(System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<InvoiceScan>>

IInvoiceProcessingService.ReadMerchant(Guid, Nullable<Guid>, CancellationToken) Method

Retrieves a merchant aggregate by identifier.

System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant> ReadMerchant(System.Guid identifier, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

identifier System.Guid

Merchant id.

parentCompanyId System.Nullable<System.Guid>

Optional partition / company scope.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task<Merchant>

IInvoiceProcessingService.ReadMerchants(Guid, CancellationToken) Method

Enumerates merchants optionally filtered by a partition / company scope.

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant>> ReadMerchants(System.Guid parentCompanyId, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

parentCompanyId System.Guid

Company / partition scope.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Merchant>>

IInvoiceProcessingService.UpdateInvoice(Invoice, Guid, Nullable<Guid>, CancellationToken) Method

Replaces an existing invoice aggregate with updated state.

System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice> UpdateInvoice(arolariu.Backend.Domain.Invoices.DDD.AggregatorRoots.Invoices.Invoice updatedInvoice, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

updatedInvoice Invoice

New aggregate state.

invoiceIdentifier System.Guid

Identifier of target invoice.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task<Invoice>
Updated invoice.

IInvoiceProcessingService.UpdateMerchant(Merchant, Guid, Nullable<Guid>, CancellationToken) Method

Replaces an existing merchant aggregate with updated state.

System.Threading.Tasks.Task<arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant> UpdateMerchant(arolariu.Backend.Domain.Invoices.DDD.Entities.Merchants.Merchant updatedMerchant, System.Guid identifier, System.Nullable<System.Guid> parentCompanyId=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

updatedMerchant Merchant

New merchant state.

identifier System.Guid

Merchant id.

parentCompanyId System.Nullable<System.Guid>

Optional company / partition scope.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task<Merchant>
Updated merchant.

IInvoiceProcessingService.UpdateMetadataOnInvoice(IDictionary<string,object>, Guid, Nullable<Guid>, CancellationToken) Method

Upserts metadata entries on an invoice (adds new keys, overwrites existing ones).

System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<string,object>> UpdateMetadataOnInvoice(System.Collections.Generic.IDictionary<string,object> metadata, System.Guid invoiceIdentifier, System.Nullable<System.Guid> userIdentifier=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

metadata System.Collections.Generic.IDictionary<System.String,System.Object>

Key/value pairs to upsert.

invoiceIdentifier System.Guid

Invoice id.

userIdentifier System.Nullable<System.Guid>

Optional partition / tenant context.

cancellationToken System.Threading.CancellationToken

Optional cancellation token to abort the operation.

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<System.String,System.Object>>
Updated metadata dictionary snapshot.

// was this page useful?