<?php

namespace App\Transformers\Assets;

use App\Models\Asset;
use App\Transformers\Users\UserTransformer;
use League\Fractal\Resource\Item;
use League\Fractal\Resource\Primitive;
use League\Fractal\TransformerAbstract;

class AssetTransformer extends TransformerAbstract {
	protected array $defaultIncludes = [
	];

	protected array $availableIncludes = [
	    'user', 'coordinates'
    ];

    public function transform(Asset $model): array {
        return [
            'id' => $model->uuid,
            'type' => $model->type,
            'path' => $model->path,
            'mime' => $model->mime,
            'name' => $model->name,
			'filename' => $model->filename,
			'extension' => $model->extension,
			'links' => $model->links(),
            'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null,
        ];
    }

    public function includeUser(Asset $model): ?Item {
    	return $model->user ? $this->item($model->user, new UserTransformer()) : null;
	}

	public function includeCoordinates(Asset $model): Primitive {
    	return $this->primitive($model->coordinates());
	}
}
