<?php

namespace App\Filament\Resources\Products\Pages;

use App\Filament\Resources\Products\ProductResource;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Cache;

class EditProduct extends EditRecord
{
    protected static string $resource = ProductResource::class;

    protected function getHeaderActions(): array
    {
        return [
            DeleteAction::make(),
        ];
    }

    /**
     * After saving a product, clear its cached API response so the
     * frontend immediately reflects the updated data.
     */
    protected function afterSave(): void
    {
        $product = $this->getRecord();

        // Clear both possible cache keys (by id and by slug)
        Cache::forget('product_detail_' . $product->id);
        Cache::forget('product_detail_' . $product->slug);
    }
}

