<?php

namespace App\Observers;

use App\Models\Area;
use App\Support\LaundryAuditLogger;

class AreaObserver
{
    public function created(Area $area): void
    {
        LaundryAuditLogger::areaConfigChanged('area.created', [
            'area_id' => $area->id,
            'code' => $area->code,
        ]);
    }

    public function updated(Area $area): void
    {
        $changes = $area->getChanges();
        unset($changes['updated_at']);
        if ($changes === []) {
            return;
        }

        LaundryAuditLogger::areaConfigChanged('area.updated', [
            'area_id' => $area->id,
            'code' => $area->code,
            'changes' => array_keys($changes),
        ]);
    }

    public function deleted(Area $area): void
    {
        LaundryAuditLogger::areaConfigChanged('area.deleted', [
            'area_id' => $area->id,
            'code' => $area->code,
        ]);
    }
}
