<?php

namespace App\Observers;

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

class InspectionObserver
{
    public function saved(Inspection $inspection): void
    {
        $this->clearReportCache($inspection->project_id);
    }

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

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