<?php

namespace App\Actions\Lead;

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

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

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

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

        return $result;
    }
}
