<?php

namespace Modules\Advertisement\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Modules\Category\Entities\Model as Category;
use Modules\Product\Entities\Model as Product;

class AdvertisementResource extends JsonResource
{
    public function toArray($request)
    {
        $type = '';
        $type_id = 0;
        $type_title = '';
        if ($this->linkable_type == Product::class) {
            $type = 'product';
            $type_id = $this->linkable_id;
            $type_title = $this->linkable->title();
        } elseif ($this->linkable_type == Category::class) {
            $type = 'category';
            $type_id = $this->linkable_id;
            $type_title = $this->linkable->title();
        }
        $arr = [
            'id' => $this->id,
            'title' => $this->title(),
            'type' => $type,
            'type_id' => $type_id,
            'type_title' => $type_title,
            'image' => asset($this->file),
        ];

        return $arr;
    }
}
