<?php

namespace App\Services;

use App\Models\Link;
use App\Enums\LinkStatus;
use Illuminate\Support\Str;

class LinkGeneratorService
{
    public function generate(\App\Models\Campaign $campaign, \App\Models\Donateur $donateur): Link
    {
        $token = Str::random(40);
        return Link::create([
            'campaign_id'   => $campaign->id,
            'donateur_id'   => $donateur->id,
            'token'         => $token,
            'status'        => LinkStatus::Pending,
        ]);
    }

    public function getLandingUrl(Link $link): string
    {
        return url("/don/{$link->campaign->slug}/{$link->token}");
    }
}
