<?php

namespace App\Observers;

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

class ChickenObserver
{
    /**
     * Handle events after any change that should invalidate chicken cache.
     */
    protected function clearChickenCache(): void
    {
        Cache::store('redis')->forget('active_chickens_for_egg_collection_form');
    }

    /**
     * Handle the Chicken "created" event.
     */
    public function created(Chicken $chicken): void
    {
        $this->clearChickenCache();
    }

    /**
     * Handle the Chicken "updated" event.
     */
    public function updated(Chicken $chicken): void
    {
        $this->clearChickenCache();
    }

    /**
     * Handle the Chicken "deleted" event.
     */
    public function deleted(Chicken $chicken): void
    {
        $this->clearChickenCache();
    }

    /**
     * Handle the Chicken "restored" event.
     */
    public function restored(Chicken $chicken): void
    {
        $this->clearChickenCache();
    }

    /**
     * Handle the Chicken "force deleted" event.
     */
    public function forceDeleted(Chicken $chicken): void
    {
        $this->clearChickenCache();
    }
}
