using Cortex.Mediator.Commands;
using CortexMediatorDemo.API.Dtos;
using Serilog;

namespace CortexMediatorDemo.API.CQRS.Commands;

public record BookPurchaseCommand(BookFroCreationDto NewBook) : ICommand;

/// <summary>
/// Handles the processing logic for the <see cref="BookPurchaseCommand"/>.
/// </summary>
/// <remarks>
/// This class is responsible for handling commands that represent a request to purchase a book.
/// It validates the input data and manages the business logic required for purchasing a book.
/// </remarks>
public class BookPurchaseCommandHandler : ICommandHandler<BookPurchaseCommand>
{
    public async Task Handle(BookPurchaseCommand command, CancellationToken cancellationToken)
    {
        try
        {
            // mock logic...
            if (string.IsNullOrWhiteSpace(command.NewBook.Isbn))
            {
                throw new ArgumentNullException(nameof(command.NewBook.Isbn));
            }
        }
        catch (Exception e)
        {
            Log.Information("#{BookPurchaseCommandHandlerName} caught exception: {EMessage}", nameof(BookPurchaseCommandHandler), e.Message);
            throw;
        }
    }
}



