<?php

namespace App\Commands\Account;

use App\Commands\Command;
use App\Models\Account;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;

class CreateAccountCommand implements Command
{
    public function execute(array $data): mixed
    {
        return DB::transaction(
            callback: fn () => Account::query()->updateOrCreate([
                'id' => $data['id'] ?? null,
                'client_id' => $data['client_id'],
            ], Arr::except($data, ['starting_balance', 'branch_id'])),
            attempts: 2
        );
    }
}
