<?php

namespace App\Actions\Balances;

use App\Actions\BaseAction;
use App\Commands\Balances\CreateBalanceCommand;
use Closure;
use Spatie\LaravelData\Data;

class CreateBalanceAction extends BaseAction
{
    public function __construct(
        private CreateBalanceCommand $createBalanceCommand
    ) {}

    public function __invoke(Data $payload, Closure $next)
    {
        $this->createBalanceCommand->execute($payload->balanceDTO->except('amount', 'type')->toArray());

        return $next($payload);
    }
}
