<?php

namespace App\Observers;

use App\Models\Expense;
use Illuminate\Support\Facades\Storage;

class ExpenseObserver
{
    /**
     * Handle the Expense "created" event.
     */
    public function created(Expense $expense): void
    {
        //
    }

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

    /**
     * Handle the Expense "deleting" event.
     */
    public function deleting(Expense $expense): void
    {
        if ($expense->attachment && $expense->attachment->formatted_attachment) {
            Storage::delete("expenses/{$expense->attachment->formatted_attachment}");
        }
    }

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

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