using Books.Api.Domain.Customers;
using EventFlow.Commands;

namespace Books.Api.Commands.Customers;

public class CreateCustomerCommandHandler : CommandHandler<CustomerAggregate, CustomerId, CreateCustomerCommand>
{
    public override Task ExecuteAsync(
        CustomerAggregate aggregate,
        CreateCustomerCommand command,
        CancellationToken cancellationToken)
    {
        aggregate.Create(
            command.CompanyId,
            command.CustomerNumber,
            command.CustomerType,
            command.Name,
            command.Cvr,
            command.Address,
            command.PostalCode,
            command.City,
            command.Country,
            command.Email,
            command.Phone,
            command.PaymentTermsDays,
            command.DefaultRevenueAccountId,
            command.SubLedgerAccountId);

        return Task.CompletedTask;
    }
}

public class UpdateCustomerCommandHandler : CommandHandler<CustomerAggregate, CustomerId, UpdateCustomerCommand>
{
    public override Task ExecuteAsync(
        CustomerAggregate aggregate,
        UpdateCustomerCommand command,
        CancellationToken cancellationToken)
    {
        aggregate.Update(
            command.Name,
            command.Cvr,
            command.Address,
            command.PostalCode,
            command.City,
            command.Country,
            command.Email,
            command.Phone,
            command.PaymentTermsDays,
            command.DefaultRevenueAccountId);

        return Task.CompletedTask;
    }
}

public class DeactivateCustomerCommandHandler : CommandHandler<CustomerAggregate, CustomerId, DeactivateCustomerCommand>
{
    public override Task ExecuteAsync(
        CustomerAggregate aggregate,
        DeactivateCustomerCommand command,
        CancellationToken cancellationToken)
    {
        aggregate.Deactivate();
        return Task.CompletedTask;
    }
}

public class ReactivateCustomerCommandHandler : CommandHandler<CustomerAggregate, CustomerId, ReactivateCustomerCommand>
{
    public override Task ExecuteAsync(
        CustomerAggregate aggregate,
        ReactivateCustomerCommand command,
        CancellationToken cancellationToken)
    {
        aggregate.Reactivate();
        return Task.CompletedTask;
    }
}
