<?php

namespace App\Domains\Api\Resources;

use App\Domains\Link\Models\Link;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/** @mixin Link */
class LinkResource extends JsonResource
{
    /** @return array<string, mixed> */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->ulid,
            'slug' => $this->slug,
            'target_url' => $this->target_url,
            'short_url' => 'https://'.config('app.short_link_domain', 'nimu.li').'/'.$this->slug,
            'status' => $this->status,
            'title' => $this->title,
            'tags' => $this->tags ?? [],
            'created_at' => $this->created_at?->toISOString(),
        ];
    }
}
