<?php

namespace App\Services;

use App\Models\Client\Client;

class ClientService {
    public function delete(Client $client, HistoryService $history) {
        // Capture the client's identity before it (and its cascade-deleted history)
        // are removed, then record the deletion against the acting user so the
        // audit trail survives the delete.
        $context = [
            'client_id'     => $client->id,
            'name'          => trim($client->name_first . ' ' . $client->name_last),
            'email'         => (string) $client->email_address,
            'date_of_birth' => optional($client->date_of_birth)->toDateString(),
            'claim_id'      => $client->claim?->id,
        ];

        $client->delete();

        $history->addForActor('Deleted client "' . $context['name'] . '"', $context);

        return true;
    }
}
