<?php

namespace App\Actions\Lead;

use App\DTOs\LeadData;
use App\Events\ModelChanged;
use App\Models\Lead;
use App\Repositories\Contracts\LeadRepositoryInterface;

final class UpdateLeadAction
{
    public function __construct(private LeadRepositoryInterface $repository) {}

    public function execute(Lead $lead, LeadData $data): Lead
    {
        $result = $this->repository->update($lead, $data->toArray());

        ModelChanged::dispatch(Lead::class, 'updated');

        return $result;
    }
}
