<?php

namespace App\Actions\GuideCard;

use App\DTOs\GuideCardData;
use App\Events\ModelChanged;
use App\Models\GuideCard;
use App\Repositories\Contracts\GuideCardRepositoryInterface;

final class CreateGuideCardAction
{
    public function __construct(private GuideCardRepositoryInterface $repository) {}

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

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

        return $result;
    }
}
