<?php

namespace App\Observers;

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

class IssueObserver
{
    public function saved(Issue $issue): void
    {
        $this->clearReportCache($issue->project_id);
    }

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

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