<?php

namespace App\Http\Resources\Api;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class BannerResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id'          => $this->id,
            'name'        => $this->name,
            'description' => $this->description,
            'image'       => $this->image ? asset('storage/' . $this->image) : null,
            'button_text' => $this->button_text,
            'link'        => $this->when(
                $this->linkable_type !== null && $this->linkable_id !== null,
                function () {
                    return [
                        'kind'  => $this->linkableApiKind(),
                        'id'    => $this->linkable_id,
                        'title' => $this->linkableTitle(),
                        // 'path'  => $this->linkableApiPath(),
                    ];
                }
            ),
            'created_at'  => $this->created_at,
            'updated_at'  => $this->updated_at,
        ];
    }
}
