<?php

namespace App\Commands\Branches;

use App\Commands\Command;
use App\Models\Branch;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;

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