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

namespace Books.Api.Commands.Companies;

public class CreateCompanyCommandHandler : CommandHandler<CompanyAggregate, CompanyId, CreateCompanyCommand>
{
    public override Task ExecuteAsync(
        CompanyAggregate aggregate,
        CreateCompanyCommand command,
        CancellationToken cancellationToken)
    {
        aggregate.Create(
            command.Name,
            command.Cvr,
            command.Address,
            command.PostalCode,
            command.City,
            command.Country,
            command.FiscalYearStartMonth,
            command.Currency,
            command.VatRegistered,
            command.VatPeriodFrequency);

        return Task.CompletedTask;
    }
}

public class UpdateCompanyCommandHandler : CommandHandler<CompanyAggregate, CompanyId, UpdateCompanyCommand>
{
    public override Task ExecuteAsync(
        CompanyAggregate aggregate,
        UpdateCompanyCommand command,
        CancellationToken cancellationToken)
    {
        aggregate.Update(
            command.Name,
            command.Cvr,
            command.Address,
            command.PostalCode,
            command.City,
            command.Country,
            command.FiscalYearStartMonth,
            command.Currency,
            command.VatRegistered,
            command.VatPeriodFrequency);

        return Task.CompletedTask;
    }
}
