<?php

namespace Ebuy\Product\Repositories\Eloquent\Presenters;

use Litepie\Repository\Presenter\Presenter;

class ProductItemPresenter extends Presenter
{

    public function itemLink()
    {
        return guard_url('product/product') . '/' . $this->getRouteKey();
    }

    public function title()
    {
        if ($this->title != '') {
            return $this->title;
        }

        if ($this->name != '') {
            return $this->name;
        }

        return 'None';
    }

    public function toArray()
    {
        return [
            'id' => $this->getRouteKey(),
            'title' => $this->title(),
            'seller_id' => $this->seller_id,
            'product_id' => $this->product_id,
            'name' => $this->name,
            'category_id' => $this->category_id,
            'brand_id' => $this->brand_id,
            'price' => $this->price,
            'tax_rate' => $this->tax_rate,
            'tax_amount' => $this->tax_amount,
            'total' => $this->total,
            'description' => $this->description,
            'model' => $this->model,
            'highlights' => $this->highlights,
            'size' => $this->size,
            'quantity' => $this->quantity,
            'services' => $this->services,
            'features' => $this->features,
            'specifications' => $this->specifications,
            'availability' => $this->availability,
            'status' => $this->status,
            'slug' => $this->slug,
            'images' => $this->images,
            'user_id' => $this->user_id,
            'user_type' => $this->user_type,
            'created_at' => !is_null($this->created_at) ? $this->created_at->format('Y-m-d H:i:s') : null,
            'updated_at' => !is_null($this->updated_at) ? $this->updated_at->format('Y-m-d H:i:s') : null,
            'meta' => [
                'exists' => $this->exists(),
                'link' => $this->itemLink(),
                'upload_url' => $this->getUploadURL(''),
            ],
        ];
    }
}