<?php

namespace App\Observers;

use App\Models\Account;
use Illuminate\Support\Facades\DB;

class AccountObserver
{
    /**
     * Handle the Account "created" event.
     */
    public function created(Account $account): void
    {
        DB::transaction(function () use ($account) {
            if (! $account->balances()->exists()) {
                $account->balances()->create([
                    'balance' => 0,
                    'is_starting' => true,
                ]);
            }
        }, 2);
    }

    /**
     * Handle the Account "updated" event.
     */
    public function updated(Account $account): void
    {
        //
    }

    /**
     * Handle the Account "deleted" event.
     */
    public function deleted(Account $account): void
    {
        //
    }

    /**
     * Handle the Account "restored" event.
     */
    public function restored(Account $account): void
    {
        //
    }

    /**
     * Handle the Account "force deleted" event.
     */
    public function forceDeleted(Account $account): void
    {
        //
    }
}
