<?php

namespace App\Observers\TodayIssue;

use App\Models\Orders\Client;
use App\Services\TodayIssueObserverService;
use Illuminate\Support\Facades\Log;

/**
 * Client 모델의 TodayIssue Observer
 */
class ClientIssueObserver
{
    public function __construct(
        protected TodayIssueObserverService $service
    ) {}

    public function created(Client $client): void
    {
        $this->safeExecute(fn () => $this->service->handleClientCreated($client));
    }

    public function deleted(Client $client): void
    {
        $this->safeExecute(fn () => $this->service->handleClientDeleted($client));
    }

    protected function safeExecute(callable $callback): void
    {
        try {
            $callback();
        } catch (\Throwable $e) {
            Log::warning('TodayIssue ClientObserver failed', [
                'error' => $e->getMessage(),
            ]);
        }
    }
}
