<?php

declare(strict_types=1);

namespace App\Observers;

use App\Models\DberpNumberSequence;
use App\Services\DberpAuditService;

final class DberpNumberSequenceObserver
{
    public function created(DberpNumberSequence $sequence): void
    {
        if (! auth()->check()) {
            return;
        }

        $audit = app(DberpAuditService::class);
        $audit->log(
            'dberp.number_sequence.created',
            $sequence,
            null,
            $audit->snapshot($sequence, $sequence->getFillable()),
        );
    }

    public function updated(DberpNumberSequence $sequence): void
    {
        if (! auth()->check()) {
            return;
        }

        $audit = app(DberpAuditService::class);
        $audit->log(
            'dberp.number_sequence.updated',
            $sequence,
            null,
            $audit->snapshot($sequence, $sequence->getFillable()),
        );
    }

    public function deleted(DberpNumberSequence $sequence): void
    {
        if (! auth()->check()) {
            return;
        }

        $audit = app(DberpAuditService::class);
        $audit->log(
            'dberp.number_sequence.deleted',
            $sequence,
            $audit->snapshot($sequence, $sequence->getFillable()),
            null,
        );
    }
}
