<?php

namespace App\Observers;

use App\Models\Feature;
use Illuminate\Support\Facades\Cache;

class FeatureObserver
{
    public function saved(Feature $feature): void
    {
        $this->clearReportCache($feature->project_id);
    }

    public function deleted(Feature $feature): void
    {
        $this->clearReportCache($feature->project_id);
    }

    private function clearReportCache(?int $projectId): void
    {
        if ($projectId) {
            Cache::tags(["report:project:{$projectId}"])->flush();
        }
    }
}